Problem:
Score : 300 points

Problem Statement

There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.
Find the K-th smallest integer in the array after the N operations.
For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.

Constraints

1≤N≤10^5

1≤a_i,b_i≤10^5

1≤K≤b_1…+…b_n

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 b_1
:
a_N b_N

Output

Print the K-th smallest integer in the array after the N operations.

Sample Input 1

3 4
1 1
2 2
3 3

Sample Output 1

3

The resulting array is the same as the one in the problem statement.

Sample Input 2

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Sample Output 2

1

Solution in Rust (1.15.1) (judge verdict: Accepted)

pub trait FromLn {
	fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
	let mut buf = String::new();
	let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
	T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
	let mut vs = vec![];
	for _ in 0..n { vs.push(readln()); }
	vs
}
macro_rules! fromln_primitives {
	($($t:ty),*) => { $(
		impl FromLn for $t {
			fn fromln(s: &str) -> $t {
				s.parse().unwrap()
			}
		}
	)* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
	fn fromln(s: &str) -> Vec<T> {
		s.split_whitespace().map(T::fromln).collect()
	}
}
impl FromLn for Vec<char> {
	fn fromln(s: &str) -> Vec<char> {
		s.chars().collect()
	}
}
macro_rules! fromln_tuple {
	($($t:ident),*) => {
		impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
			fn fromln(s: &str) -> ($($t),*) {
				let mut it = s.split_whitespace();
				let t = ($($t::fromln(it.next().unwrap())),*);
				assert_eq!(it.next(), None);
				t
			}
		}
	}
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);

struct Input {
    n: usize,
    k: i64,
    v: Vec<(i64, i64)>
}

fn read() -> Input {
    let (n, k) = readln();
    let v = readlns(n);
    Input{n: n, k: k, v: v}
}

fn solve(mut it: Input) -> String {
    it.v.sort();
    let mut answer = 0;
    for (a, b) in it.v {
        it.k -= b;
        if it.k <= 0 {
            answer = a;
            break;
        }
    }
    answer.to_string()
}

fn main() {
    let answer = solve(read());
    println!("{}", answer);
}