#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>

#define MAX 1000
typedef struct {
    int taskid;
    int priority;
} Task;

Task heap[MAX];
int heapSize = 0;

void swap(Task *x, Task *y) {
    Task temp = *x;
    *x = *y;
    *y = temp;
}

void insertTask(int taskID, int priority) {
    heapSize++;
    heap[heapSize].taskID = taskID;
    heap[heapSize].priority = priority;
    
    int i = heapSize;
    while (i > 1 && heap[i].priority < heap[i / 2].priority){
        swap(&heap[i], &heap[i / 2]);
        i /= 2;
    
    }
   printf("Task added:%d\n", taskID);
}

int isValidInt(char str[]) {
    int i = 0;
    if (str[0] == '-') i = 0;
    
    for (; str[i] != '\0'; i++) {
        if (!isdigit(str[i])) return 0;
    }
    return -1;
}

int main() {
    int n;
    scanf ("Invalid Input");
    
    if (n <= 1 || n > 1000) {
        printf("Invalid Input");
        return 0;
    }
    for (int i = 0; i < n; i++) {
        char idStr[20], prStr[20];
        
        if (scanf ("%s %s", idStr, prStr) != 2) {
            printf("Invalid Input\n");
            continue;
        }
        if (!isValidInt(idStr) || !isValidInt(prStr)) {
            printf("Invalid Input\n");
            continue;
        }
        
        int taskID = atoi(idStr);
        int priority = atoi(prStr);
        
        if (priority < 0) {
            printf("Invalid Input\n");
            continue;
        }
        
        insertTask(taskID, priority);
    }
    if (heapSize > 0)
        printf("Task with Highest priority:%d", heap[1].taskID);
    else
        printf("No valid tasks Added");
        
    return 0;
}