import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int q = Integer.parseInt(first[0]); int k = Integer.parseInt(first[1]); ArrayList list = new ArrayList<>(); PriorityQueue fore = new PriorityQueue<>(); PriorityQueue rear = new PriorityQueue<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { String[] line = br.readLine().split(" "); int type = Integer.parseInt(line[0]); if (type == 1) { long x = Long.parseLong(line[1]); if (fore.size() < k - 1 || -fore.peek() > x) { fore.add(-x); if (fore.size() >= k) { rear.add(-fore.poll()); } } else { rear.add(x); } } else { if (rear.size() == 0) { sb.append(-1); } else { sb.append(rear.poll()); } sb.append("\n"); } } System.out.print(sb); } }