import std.algorithm; import std.array; import std.container; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto qk = readints; int q = qk[0], k = qk[1]; auto q1 = new BinaryHeap!(Array!long, "a < b"); auto q2 = new BinaryHeap!(Array!long, "a > b"); for (int i = 0; i < q; i++) { string s = readln; if (s[0] == '1') { long x = s[2..$-1].to!long; if (q1.length < k) { q1.insert(x); } else { if (q1.front <= x) { q2.insert(x); } else { q1.insert(x); q2.insert(q1.front); q1.popFront; } } } else { if (q1.length < k) { writeln(-1); } else { writeln(q1.front); q1.popFront; if (q2.length > 0) { q1.insert(q2.front); q2.popFront; } } } } }