// Arup Guha
// 10/28/2026
// Task class to use for Priority Queue example
// Solution to old Program from COP 3330. Also uses Task class.

import java.util.*;

public class whattask {

	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numRequests = stdin.nextInt();
		
		// PQ for our jobs
		PriorityQueue<Task> myPQ = new PriorityQueue<Task>();
		
		// Process requests.
		for (int loop=0; loop<numRequests; loop++) {
		
			int cmd = stdin.nextInt();
			
			// Ugh more work...
			if (cmd == 1) {
				
				// Read in info, create object add to PQ.
				String myTask = stdin.next();
				int myMoney = stdin.nextInt();
				myPQ.add(new Task(myTask, myMoney));
			}
			
			// I'll actually do something and print it out...
			else {
				System.out.println(myPQ.poll());
			}
		}
	}
}