#include<stdio.h>
#include<stdlib.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 heapifyUp(int index){
    if(index<=0)
    return;
    int parent=(index-1)/2;
    if(heap[index].p<heap[parent].p){
      swap(&heap[index],&heap[parent]);
      heapifyUp(parent);
    }
}
void heapifyDown(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;
    int(right<heap[right].p<heap[smallest].p)
    smallest=right;
    if(smallest !=index){
        swap(&heap[index],&heap[smallest]);
        heapifyDown(smallest);
    }
}
void insert(int id,int p){
    heap[size].id=id;
    heap[size].p=p;
    heapifyUp(size);
    size++;
    printf("Task Added:%d\n",id);
}
int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d %d",&taskid,&p);
        int taskid,p;
        if(taskid < 0 || p < 0){
            printf("Invalid input\n");
            continue;
        }
        insert(taskid,p);
    }
    printf("task with highest priority: %d\n",heap[0],taskid);
    return 0;
}