use std::{ collections::{BTreeSet, HashMap, HashSet, VecDeque}, fmt::Debug, io::stdin, str::FromStr, }; use proconio::marker::Chars; fn main() { // proconio::input! { // q: usize, // k: usize, // } let x = read::(); let (q, k) = (x[0], x[1]); let k = k as usize; let mut query = (0..q) .flat_map(|_| read::()) .enumerate() .map(|v| (v.1, v.0)); let mut s = BTreeSet::new(); let mut t = BTreeSet::new(); while let Some(q) = query.next() { match q.0 { 1 => { let val = query.next().unwrap(); if s.len() == k { t.insert(s.pop_last().unwrap()); t.insert(val); s.insert(t.pop_first().unwrap()); } else { s.insert(val); } } 2 => { if s.len() < k as usize { println!("-1"); } else { println!("{}", s.pop_last().unwrap().0); if let Some(x) = t.pop_first() { s.insert(x); } } } _ => unreachable!(), } } } fn read() -> Vec where T: FromStr, ::Err: Debug, { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); s.split(' ').map(|v| v.trim().parse().expect(v)).collect() }