#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#define MAX 1000
 struct task{
     int id;
     int p;
 };
  struct task heap[MAX];
 int size = 0;
 
 void swap(struct task*a,struct task*b){
     struct task temp = *a;
     *a = *b;
     *b = temp;
 } 
 
 void heapify_up(int index) {
     if(index <= 0) return;
     int parent = (index - 1) / 2;
         if(heap[index].p<heap[parent].p) {
         swap(&heap[index], &heap[parent]);
         heapify_up(parent);
     }
 }
 void heapify_down(int index) {
     int left = 2 * index + 1;
     int right= 2 * index + 2;
     int smallest = index;
     if(left < size && heap[left].p<heap[smallest].p)
        smallest=left;
     if(right < size && heap[right].p<heap[smallest].p)
        smallest=right;
        
     if(smallest != index) {
    swap(&heap[index], &heap[smallest]);
    heapify_down(smallest);
     }
 }
 void insert(int id, int p){
     heap[size].id = id;
     heap[size].p = p;
     heapify_up(size);
     size++;
     printf("Task Added: %d\n", id);
 }
  struct task extract_task() {
  struct task min_task = heap[0];
  heap[0] = heap[size-1];
  size--;
  heapify_down(0);
  return min_task;
  }
  int main(){
       int n;
       scanf("%d", &n);
       for (int i = 0; i < n; i++) {
           int id, p;
           scanf("%d %d", &id, &p);
       
           if (scanf("%!= 1 || x < 1 || x > 1000) {
                   printf("Invalid input\n");
                    continue;
               }
               insert(x, x);
           }
           
            if (size > 0)
                   printf("Task with Highest Priority: %d\n", heap[0].id);
            else 
               printf("no valid tasks\n");
               
       return 0;
       
           }