def sort(array) b = false ary = array.dup pos_max = ary.length - 1 (0...(pos_max)).each{|n| (0...(pos_max - n)).each{|ix| iy = ix + 1 if ary[ix] > ary[iy] then ary[ix], ary[iy] = ary[iy], ary[ix] else b = true break end } break if b } ary end q, k = gets.split.map(&:to_i) s = [] q.times{ if v = gets.split.map(&:to_i)[1] then if s == [] || v >= s[-1] then s.push(v) elsif v <= s[0] then s.unshift(v) else s.unshift(v) s = sort(s) end else puts s.size >= k ? s.delete_at(k - 1) : -1 end }