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