use std::str::SplitWhitespace; use std::str::FromStr; use std::io::BufWriter; use std::io::Write; use std::io::Read; struct Scanner<'a> { it: SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } } use std::collections::BinaryHeap; use std::cmp::Reverse; fn run() { let s = { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut sc = Scanner {it: s.split_whitespace()}; let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); let q: usize = sc.next(); let k: usize = sc.next(); let mut small = BinaryHeap::new(); let mut large = BinaryHeap::new(); for _ in 0..q { let op: u8 = sc.next(); if op == 1 { let v: u64 = sc.next(); small.push(v); if small.len() >= k { large.push(Reverse(small.pop().unwrap())); } } else if let Some(Reverse(v)) = large.pop() { writeln!(out, "{}", v).unwrap(); } else { writeln!(out, "-1").unwrap(); } } } fn main() { run(); }