#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::*; #[allow(unused_imports)] use std::mem::*; fn solve(mut io: Reader) { let n = io.read(); let ww: i32 = io.read(); let mut vw = vec![(0, 0); n]; for (v, w) in &mut vw { *v = io.read(); *w = io.read(); } println!( "{}", vw.into_iter() .filter(|&(_, w)| w <= ww) .map(|x| x.0) .max() .unwrap_or(-1) ); } // Reader fn main() { let reader = Reader::new(); solve(reader); STDOUT.with(|cell| cell.borrow_mut().flush().ok()); } struct Reader<'a> { buf: Vec, off: usize, len: usize, stdin: StdinLock<'a>, } const BUFFER_SIZE: usize = 1 << 17; impl Reader<'_> { fn new() -> Self { Self { buf: vec![0; BUFFER_SIZE], off: BUFFER_SIZE, len: BUFFER_SIZE, stdin: stdin().lock(), } } fn skip_whitespace(&mut self) { while self.len > 0 { if let Some(i) = self.buf[self.off..self.len].iter().position(|&b| b > b' ') { self.off += i; break; } self.fill(); } } fn remain(&self) -> &[u8] { &self.buf[self.off..self.len] } #[cold] fn fill(&mut self) { let len = self.stdin.read(&mut self.buf).unwrap(); self.len = len; self.off = 0; } fn read(&mut self) -> T { self.skip_whitespace(); T::from_reader(self) } } trait Readable { fn from_reader(r: &mut Reader) -> Self; } impl Readable for String { fn from_reader(r: &mut Reader) -> Self { let mut s = Self::new(); while r.len > 0 { let remain = r.remain(); if let Some(i) = remain.iter().position(|&b| b <= b' ') { unsafe { s.as_mut_vec() }.extend_from_slice(&remain[..i]); r.off += i; break; } else { unsafe { s.as_mut_vec() }.extend_from_slice(remain); } r.fill(); } s } } struct Line(String); impl Readable for Line { fn from_reader(r: &mut Reader) -> Self { let mut s = String::new(); while r.len > 0 { let remain = r.remain(); if let Some(i) = remain.iter().position(|&b| b < b' ') { unsafe { s.as_mut_vec() }.extend_from_slice(&remain[..i]); r.off += i; break; } else { unsafe { s.as_mut_vec() }.extend_from_slice(remain); } r.fill(); } Line(s) } } macro_rules! readable_signed { ($($t:ty)+) => { $( impl Readable for $t { fn from_reader(r: &mut Reader) -> Self { let mut neg = None; let mut x = 0u64; 'next_char: while r.len > 0 { for (i, &b) in r.remain().iter().enumerate() { if b == b'-' && neg.is_none() { neg = Some(true); } else if b.is_ascii_digit() { x = x * 10 + b as u64 - 48; } else { r.off += i; break 'next_char; } } r.fill(); } if neg == Some(true) { x.wrapping_neg() as $t } else { x as $t } } } )+ }; } macro_rules! readable_unsigned { ($($t:ty)+) => { $( impl Readable for $t { fn from_reader(r: &mut Reader) -> Self { let mut x = 0; 'next_char: while r.len > 0 { for (i, &b) in r.remain().iter().enumerate() { if b.is_ascii_digit() { x = x * 10 + b as $t - 48; } else { r.off += i; break 'next_char; } } r.fill(); } x } } )+ }; } readable_signed!(i8 i16 i32 i64 i128 isize); readable_unsigned!(u8 u16 u32 u64 u128 usize); thread_local! { static STDOUT: std::cell::RefCell>> = std::cell::RefCell::new(std::io::BufWriter::with_capacity(1 << 17, stdout().lock())); } #[macro_export] macro_rules! println { ($($t:tt)*) => { STDOUT.with(|cell| writeln!(cell.borrow_mut(), $($t)*).unwrap()); }; } #[macro_export] macro_rules! print { ($($t:tt)*) => { STDOUT.with(|cell| write!(cell.borrow_mut(), $($t)*).unwrap()); }; } #[macro_export] macro_rules! flush { () => { STDOUT.with(|cell| cell.borrow_mut().flush().unwrap()); }; }