#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX_TASKS 1000

// Task structure
struct Task {
    int taskID;
    int priority;
};

// Min-Heap
struct Task heap[MAX_TASKS];
int heapSize = 0;

// Swap two tasks
void swap(struct Task *a, struct Task *b) {
    struct Task temp = *a;
    *a = *b;
    *b = temp;
}

// Heapify up
void heapifyUp(int index) {
    while (index > 0) {
        int parent = (index - 1) / 2;
        if (heap[parent].priority > heap[index].priority) {
            swap(&heap[parent], &heap[index]);
            index = parent;
        } else {
            break;
        }
    }
}

// Insert into heap
void insertTask(int taskID, int priority) {
    struct Task newTask;
    newTask.taskID = taskID;
    newTask.priority = priority;

    heap[heapSize] = newTask;
    heapifyUp(heapSize);
    heapSize++;
}

// Validate integer input
int isValidInteger(char *str) {
    if (*str == '-' || *str == '+') str++; // Allow negative or positive sign
    if (!*str) return 0;
    while (*str) {
        if (!isdigit(*str)) return 0;
        str++;
    }
    return 1;
}

int main() {
    int n;
    scanf("%d", &n);
    getchar(); // consume newline

    if (n < 1 || n > MAX_TASKS) {
        printf("Invalid input\n");
        return 0;
    }

    for (int i = 0; i < n; i++) {
        char line[100];
        int taskID, priority;
        fgets(line, sizeof(line), stdin);

        // Parse and validate
        char *token1 = strtok(line, " \n");
        char *token2 = strtok(NULL, " \n");

        if (!token1 || !token2 || !isValidInteger(token1) || !isValidInteger(token2)) {
            printf("Invalid input\n");
            continue;
        }

        taskID = atoi(token1);
        priority = atoi(token2);

        if (priority < 0) {
            printf("Invalid input\n");
            continue;
        }

        insertTask(taskID, priority);
        printf("Task Added: %d\n", taskID);
    }

    if (heapSize > 0) {
        printf("Task with Highest Priority: %d\n", heap[0].taskID);
    }

    return 0;
}