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); auto q2 = new BinaryHeap!(Array!long); for (int i = 0; i < q; i++) { auto xs = reads!long; if (xs.length > 1) { q1.insert(xs[1]); if (q1.length > k) { 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; } } } } }