#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAX_SIZE 1000
typedef struct{
    int taskID;
    int priority;
}Task;
Task heap[MAX_SIZE];
int heapSize =0;
void swap(Task *a,Task *b){
    Task temp = *a;
    *a = *b;
    *b =temp;
}
void minHeapIfy(int idx){
    int smallest = idx;
    int left = 2 * idx+1;
    int right = 2 * idx+2;
    
    if(left<heapSize && heap[left].priority< heap[smallest].priority)
    smallest = left;
    
    if(right<heapSize && heap[right].priority< heap[smallest].priority)
    smallest = right;
    
    if(smallest !=idx){
        swap(&heap[idx],&heap[smallest]);
        minHeapIfy(smallest);
    }
}

void insertTask(int taskID, int priority){
    if(heapSize >= MAX_SIZE){
        return;
    }
    heap[heapSize].taskID=taskID;
    heap[heapSize].priority = priority;
    int i = heapSize;
    heapSize++;
    
    while(i !=0&& heap[(1-1)/2].priority > heap[i].priority){
        swap(&heap[i],&heap[(i-1)/2]);
        i=(i-1)/2;
    }
}
Task getHighestpriorityTask(){
    if(heapSize <=0){
        Task nullTask = {-1,INT_MAX};
        return nullTask;
    }
    return heap[0];
}

int main(){
    int n;
    if(scanf("%d",&n)!=1){
        printf("Invalid input");
        return 0;
}
if(n<1||n>1000){
    printf("Invalid input");
    return 0;
}
for(int i=0;i<n;i++){
    int taskID,priority;
    
    if(scanf("%d %d",&taskID,&priority)!=2){
        printf("Invalid input");
        return 0;
    }
    if(taskID<0||priority<0){
        printf("Invalid input");
        return 0;
    }
    insertTask(taskID,priority);
    printf("Task Added: %d\n",taskID);
}
Task highest = getHighestPriorityTask();
if(highest.taskID !=-1){
    printf("Task with Highest priority: %d",highest.taskID);
}else{
    printf("NO tasks available");
}
return 0;
}