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 Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ss0 = br.readLine().trim().split(" ", 0);
		int N = Integer.parseInt(ss0[0]);
		int K = Integer.parseInt(ss0[1]);
		
		Map<Long, Long> m = new HashMap<Long, Long>();

		
		//long[] key = new long[N];
		//long[] val = new long[N];
		long count=0L;
		long min=Long.MAX_VALUE;
		long max=0L;
		
		long kosu=0L;
		long atai=0L;
		
		long key;
		long x;
		long val;
		long ans=0L;
		for(int i=0; i<N; i++){
			ss0 = br.readLine().trim().split(" ", 0);
			key = Long.parseLong(ss0[0]);
			val = Long.parseLong(ss0[1]);
			
			//System.out.println("key=[" + key + "], val=[" + val + "]");
			
			if(atai == 0L) { atai = key; }
			
			kosu += val;
			if(kosu > K){
				if(atai <= key) {
					if(m.containsKey(key)){
						val += m.get(key);
						m.remove(key);
					}
					m.put(key, val);
					atai = key;
				}
			}else{
				m.put(key, val);
				if(atai < key) {
					atai = key;
				}
			}
			
			//System.out.println("atai=[" + atai + "], kosu=[" + kosu + "]");
		}

        // List 生成 (ソート用)
        List<Map.Entry<Long, Long>> entries =  new ArrayList<Map.Entry<Long, Long>>(m.entrySet());
        Collections.sort(entries, new Comparator<Map.Entry<Long, Long>>() {
            @Override
            public int compare(
                  Entry<Long, Long> entry1, Entry<Long, Long> entry2) {
                return ((Long)entry1.getValue()).compareTo((Long)entry2.getValue());
            }
        });		
		
        // 内容を表示
        for (Entry<Long, Long> s : entries) {
            //System.out.println("s.getKey()=[" + s.getKey() + "], s.getValue()=[" + s.getValue() + "], count=[" + count + "]");
            
			//System.out.println("count=[" + count + "]");
            count += s.getValue();
            if(count >= K){
				ans = s.getKey();
				break;
			}
        }
//		System.out.println("count=[" + count + "]");
        
        System.out.println(ans);
        return;
    }


}