// Arup Guha
// 10/28/2026
// This is an inefficient implementation of the whattask program written
// to show how slow an O(n^2) algorithm runs for n = 200,000.

import java.util.*;

public class whattask_slow {

	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numRequests = stdin.nextInt();
		
		// PQ for our jobs
		ArrayList<Task> myList = new ArrayList<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();
				myList.add(new Task(myTask, myMoney));
			}
			
			// I'll actually do something and print it out...
			else {
			
				// For an unordered list, best I can do is loop through it.
				int res = 0;
				for (int i=1; i<myList.size(); i++) {
					if (myList.get(i).compareTo(myList.get(res)) < 0)
						res = i;
				}
				
				// Ta da!
				System.out.println(myList.remove(res));
			}
		}
	}
}