#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define MAX 1000
struct Task{
    int taskID;
    int priority;
};
void swap(struct Task *a, struct Task *b){
    struct Task temp = *a;
    *a = *b;
    *b = temp;
}
void heapifyUp(struct Task heap[], int index){
    int parent = (index - 1) / w;
    while (index > 0 && heap[index].priority < heap[parent].priority){
        swap(&heap[index],&heap[parent]);
        index = parent;
        parent = (index - 1) / 2;
    }
}
void heapifyDown(struct Task heap[], int size, int index){
    int smallest = index;
    int left = 2 * index + 1;
    int right = 2 * index + 2;
    if (left < size && heap[left].priority < heap[smallest].priority)
    smallest = left;
    if (smallest != index){
        swap (&heap[index],&heap[smallest]);
        heapifyDown(heap, size, smallest);
    }
    
}
int isinteger(char *str){
    if(*str == '-' || *str == '+') str++;
    while(*str){
        if(!isdigit(*str))return 0;
        str++;
    }
    return 1;
}
int main(){
    int n;
    scanf("%d",&n);
    struct Task heap[MAX];
    int size = 0;
    for (int i = 0; i < n; i++){
        char idstr[50], priostr[50];
        scanf("%s %s", idstr, priostr);
        if(!isInteger(idstr) || !isInteger(priostr)){
            printf("Invalid Input\n");
            continue;
        }
        int taskID=atoi(idstr);
        int priority=atoi(priostr);
        if(priority < 0) {
            printf("Invalid Input\n");
            continue;
        }
        heap[size].taskID=taskID;
        heap[size].priority=priority;
        size++;
        printf("Task Added: \n%d\n",taskID);
    }
    if (size > 0) {
        printf("Task with\nHighest Priority: %d\n",heap[0].taskID);
    }
    else{
        printf("No valid tasks added\n");
    }
    return 0;
}