AtCoder Beginner Contest 061 - Big Array

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-----
3 4
1 1
2 2
3 3

-----Sample Output-----
3

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

Difficulty: EASY

Starter code:

Solutions:
(n, k) = map(int, input().split())
i = 0
a = sorted((list(map(int, input().split())) for _ in [0] * n))
while k > 0:
	k -= a[i][1]
	i += 1
print(a[~-i][0])


((N, K), *AB) = [list(map(int, s.split())) for s in open(0)]
for (a, b) in sorted(AB):
	K -= b
	if K <= 0:
		print(a)
		break


(n, k) = map(int, input().split())
l = [0] * (10 ** 5 + 1)
for i in range(n):
	(a, b) = map(int, input().split())
	l[a] += b
sm = 0
for i in range(1, 10 ** 5 + 1):
	sm += l[i]
	if sm >= k:
		print(i)
		break


(N, K) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
x.sort()
ans = 0
for v in x:
	ans = v[0]
	K -= v[1]
	if K <= 0:
		break
print(ans)


(n, k) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
for (a, b) in AB:
	k -= b
	if k <= 0:
		print(a)
		break


(N, K) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in [0] * N])
for (a, b) in ab:
	K -= b
	if K <= 0:
		print(a)
		break


(n, k) = map(int, input().split())
lst = [0] * 10 ** 5
for i in range(n):
	(a, b) = map(int, input().split())
	lst[a - 1] += b
	ans = 0
for j in range(10 ** 5):
	ans += lst[j]
	if ans >= k:
		print(j + 1)
		return


(n, k) = map(int, input().split())
a_b = [list(map(int, input().split())) for _ in range(n)]
a_b = sorted(a_b, key=lambda x: x[0])
count = 0
for i in range(len(a_b)):
	(a, b) = a_b[i]
	count += b
	if count >= k:
		print(a)
		break


(n, k) = map(int, input().split())
l = [0] * 10 ** 5
for i in range(n):
	(a, b) = map(int, input().split())
	l[a - 1] += b
sum = 0
i = 0
while sum < k:
	sum += l[i]
	i += 1
print(i)


(n, k) = list(map(int, input().split()))
li = []
for i in range(n):
	temp = list(map(int, input().split()))
	li.append(temp)
li.sort()
total = 0
for i in range(n):
	if i == n - 1:
		print(li[i][0])
		break
	total += li[i][1]
	if total < k:
		continue
	else:
		print(li[i][0])
		break


(n, m) = map(int, input().split())
lis = [list(map(int, input().split())) for i in range(n)]
cou = 0
lis.sort()
for i in range(n):
	cou += lis[i][1]
	if cou >= m:
		print(lis[i][0])
		exit()


import heapq
(n, k) = map(int, input().split())
q = []
for i in range(n):
	q.append(list(map(int, input().split())))
heapq.heapify(q)
cnt = 0
while cnt < k:
	(a, b) = heapq.heappop(q)
	cnt += b
print(a)


(n, k) = [int(i) for i in input().split()]
m = sorted([[int(i) for i in input().split()] for _ in range(n)])
s = 0
i = 0
while s < k:
	s += m[i][1]
	i += 1
print(m[i - 1][0])


(N, K) = map(int, input().split())
A = {}
for i in range(N):
	(a, b) = map(int, input().split())
	A[a] = A.get(a, 0) + b
A = sorted(A.items())
cnt = 0
for (n, k) in A:
	cnt += k
	if cnt >= K:
		print(n)
		return


(n, k) = map(int, input().split())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
l = sorted(l)
c = 0
i = 0
while c < k:
	c += l[i][1]
	i += 1
print(l[i - 1][0])


(N, K) = map(int, input().split())
s = sorted([list(map(int, input().split())) for i in range(N)])
t = 0
while K > 0:
	K -= s[t][1]
	t += 1
print(s[t - 1][0])


(N, K) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
k = K
i = 0
while k > 0:
	k -= A[i][1]
	ans = A[i][0]
	i += 1
print(ans)


(N, K) = map(int, input().split())
s = 0
ab = [[0, 0] for i in range(N)]
for i in range(N):
	(ab[i][0], ab[i][1]) = map(int, input().split())
ab = sorted(ab)
for i in range(N):
	s += ab[i][1]
	if s >= K:
		print(ab[i][0])
		break


(N, K) = [int(i) for i in input().split()]
(a, b) = ([], [])
for _ in range(N):
	tmp = input().split()
	a.append(int(tmp[0]))
	b.append(int(tmp[1]))
cnt = [0] * (100000 + 1)
for i in range(N):
	cnt[a[i]] += b[i]
for j in range(100000 + 1):
	if K <= cnt[j]:
		print(j)
		break
	K -= cnt[j]


(N, K) = map(int, input().split())
ab = list(sorted([list(map(int, input().split())) for _ in range(N)]))
a = 0
for i in range(N):
	a += ab[i][1]
	if a >= K:
		print(ab[i][0])
		exit()


(n, k) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
x = 0
s.sort()
for i in range(n):
	x += s[i][1]
	if k <= x:
		print(s[i][0])
		exit()


(n, k) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
c = 0
for i in range(n):
	c += li[i][1]
	if c >= k:
		print(li[i][0])
		break


(n, k) = [int(i) for i in input().split()]
ab = sorted([[int(j) for j in input().split()] for _ in range(n)], key=lambda x: x[0])
for (a, b) in ab:
	k -= b
	if k <= 0:
		print(a)
		break


(n, k) = [int(i) for i in input().split()]
a = [[int(j) for j in input().split()] for _ in range(n)]
a.sort()
x = 0
i = 0
while 1:
	if k <= 0:
		break
	else:
		k -= a[i][1]
		i += 1
print(a[i - 1][0])


(N, K) = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
A = sorted(A, key=lambda x: x[0])
cnt = 0
for i in range(N):
	(a, b) = A[i]
	A[i][1] += cnt
	cnt = A[i][1]
for i in range(N):
	(a, b) = A[i]
	if K <= b:
		break
print(a)


M = lambda : map(int, input().split())
(n, k) = M()
r = []
for _ in [0] * n:
	r.append(list(M()))
for (x, y) in sorted(r):
	k -= y
	if k < 1:
		print(x)
		exit()


(n, k) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
x = 0
for (a, b) in ab:
	x += b
	if x >= k:
		print(a)
		break


(n, k) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
cnt = 0
for i in ab:
	cnt += i[1]
	if cnt >= k:
		print(i[0])
		exit(0)


(n, k) = map(int, input().split())
ll = sorted([list(map(int, input().split())) for _ in [0] * n], key=lambda x: x[0])
s = 0
for l in ll:
	s += l[1]
	if s >= k:
		print(l[0])
		break


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
for i in range(n):
	k -= a[i][1]
	if k <= 0:
		print(a[i][0])
		break


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cnt = 0
for (a, b) in ab:
	cnt += b
	if cnt >= k:
		break
print(a)


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
cnt = 0
for (a, b) in ab:
	cnt += b
	if cnt >= k:
		print(a)
		exit()


(n, K) = map(int, input().split())
c = {}
for i in range(n):
	(a, b) = map(int, input().split())
	if a in c:
		c[a] += b
	else:
		c[a] = b
for (k, v) in sorted(c.items()):
	K -= v
	if K <= 0:
		print(k)
		exit()


(N, K) = map(int, input().split())
d = {}
for i in range(N):
	(a, b) = map(int, input().split())
	if a not in d:
		d[a] = b
	else:
		d[a] += b
d = sorted(d.items())
for i in d:
	K -= i[1]
	if K <= 0:
		print(i[0])
		break


(N, K) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)])
c = 0
for ab in AB:
	c += ab[1]
	if c >= K:
		exit(print(ab[0]))


(N, K) = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(N)]
arr.sort()
n = 0
for i in range(N):
	n += arr[i][1]
	if n >= K:
		print(arr[i][0])
		break


(N, K) = map(int, input().split())
d = []
for i in range(N):
	(a, b) = map(int, input().split())
	d.append((a, b))
d.sort(reverse=True)
while K > 0:
	(a, b) = d.pop()
	K -= b
print(a)


(N, K) = map(int, input().split())
A = {}
for n in range(N):
	(a, b) = map(int, input().split())
	A[a] = A.get(a, 0) + b
for key in sorted(list(A.keys())):
	K -= A[key]
	if K <= 0:
		print(key)
		break


(n, k) = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(n)])
now = 0
for (key, v) in l:
	if v + now >= k:
		print(key)
		exit()
	now += v


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
cnt = 0
i = 0
while cnt < k:
	cnt += a[i][1]
	i += 1
print(a[i - 1][0])


(n, k) = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(n)])
for (a, b) in l:
	k -= b
	if k < 1:
		print(a)
		break


(n, k) = map(int, input().split())
A = [tuple(map(int, input().split())) for i in range(n)]
A.sort(key=lambda x: x[0])
m = 0
i = -1
while m < k:
	i += 1
	m += A[i][1]
print(A[i][0])


(N, K, *L) = [int(a) for a in open(0).read().split()]
for (a, b) in sorted(zip(L[::2], L[1::2])):
	K -= b
	if K < 1:
		print(a)
		return


(N, K) = map(int, input().split())
array = [0] * (10 ** 5 + 1)
for i in range(N):
	(a, b) = map(int, input().split())
	array[a] += b
S = 0
i = 0
while S < K:
	S += array[i]
	i += 1
print(i - 1)


(N, K) = list(map(int, input().split()))
ab = list((list(map(int, input().split())) for _ in range(N)))
ab.sort()
i = 0
while K > 0:
	K -= ab[i][1]
	i += 1
print(ab[i - 1][0])


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
i = -1
while k > 0:
	i += 1
	k -= ab[i][1]
print(ab[i][0])


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
count = 0
for (a, b) in ab:
	count += b
	if k <= count:
		print(a)
		exit()


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 998244353

def readInts():
	return list(map(int, input().split()))

def I():
	return int(input())
from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 998244353

def readInts():
	return list(map(int, input().split()))

def I():
	return int(input())
(n, k) = readInts()
dic = defaultdict(int)
d = set()
for i in range(n):
	(a, b) = readInts()
	d.add(a)
	dic[a] += b
d = sorted(list(d))
ans = 0
for v in d:
	if ans + dic[v] >= k:
		print(v)
		return
	ans += dic[v]


(n, k, *l) = map(int, open(0).read().split())
for (a, b) in sorted(zip(l[::2], l[1::2])):
	k -= b
	if k < 1:
		print(a)
		exit()


def main():
	(N, K) = list(map(int, input().split()))
	l = []
	cnt = 0
	for _ in range(N):
		(a, b) = list(map(int, input().split()))
		l.append((a, b))
	l.sort(key=lambda x: x[0])
	for (a, x) in l:
		cnt += x
		if cnt >= K:
			print(a)
			return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in range(n)])
c = 0
for (a, b) in l:
	c += b
	if c >= k:
		print(a)
		exit(0)


(n, k) = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
for (a, b) in ab:
	k -= b
	if k <= 0:
		print(a)
		exit()


(N, K) = map(int, input().split())
d = {}
key = set([])
for _ in range(N):
	(a, b) = map(int, input().split())
	if a in key:
		d[str(a)] += b
	else:
		key.add(a)
		d[str(a)] = b
key = sorted(list(key))
for k in key:
	if d[str(k)] < K:
		K -= d[str(k)]
	else:
		print(k)
		break


(N, K) = list(map(int, input().split()))
count = [0] * 100001
for i in range(1, N + 1):
	(a, b) = list(map(int, input().split()))
	count[a] += b
for i in range(1, 100001):
	if K <= count[i]:
		print(i)
		break
	K -= count[i]


from xml.dom import minidom
(n, k) = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
now = -1
idx = 0
while k > 0:
	if idx >= n:
		break
	(a, b) = AB[idx]
	k -= b
	now = a
	idx += 1
print(now)


(N, K) = map(int, input().split())
arr = sorted([list(map(int, input().split())) for i in range(N)])
total = 0
for i in range(N):
	total += arr[i][1]
	if total >= K:
		print(arr[i][0])
		exit()


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab)
now = 0
for (a, b) in ab:
	now += b
	if now >= k:
		print(a)
		exit()


(N, K) = map(int, input().split())
A = sorted([list(map(int, input().split())) for k in range(N)])
for a in A:
	K -= a[1]
	if K <= 0:
		print(a[0])
		exit(0)


(N, K) = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x: x[0])
i = 0
while K - AB[i][1] > 0:
	K -= AB[i][1]
	i += 1
print(AB[i][0])


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]
import string

def main():
	(n, k) = i_map()
	cnt = 0
	l = []
	for _ in range(n):
		(a, b) = i_map()
		l.append([a, b])
	l.sort()
	for (i, j) in l:
		cnt += j
		if cnt >= k:
			print(i)
			break

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
A.sort()
s = 0
for i in range(n):
	s += A[i][1]
	if s >= k:
		print(A[i][0])
		break


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
c = 0
i = 0
a.sort(key=lambda a: a[0])
while c < k:
	c += a[i][1]
	i += 1
print(a[i - 1][0])


li = [0] * (10 ** 5 + 10)
(n, k) = map(int, input().split())
for i in range(n):
	(a, b) = map(int, input().split())
	li[a] += b
cnt = 0
ans = 0
for i in range(10 ** 5 + 10):
	cnt += li[i]
	ans = i
	if cnt >= k:
		break
print(ans)


(N, K) = map(int, input().split())
ls = [0] + [0] * 10 ** 5
for i in range(N):
	(a, b) = map(int, input().split())
	ls[a] += b
ii = 0
for i in range(1, 10 ** 5 + 1):
	ii += ls[i]
	if ii >= K:
		ans = i
		break
	else:
		continue
print(ans)


AMAX = 10 ** 5
count = [0] * (AMAX + 1)
(N, K) = map(int, input().split())
for _ in range(N):
	(a, b) = map(int, input().split())
	count[a] += b
for ans in range(AMAX + 1):
	if K <= count[ans]:
		print(ans)
		break
	K -= count[ans]


(n, k) = map(int, input().split())
cnt = [0] * (10 ** 5 + 1)
for _ in range(n):
	(a, b) = map(int, input().split())
	cnt[a] += b
tmp = 0
for i in range(10 ** 5 + 1):
	tmp += cnt[i]
	if tmp >= k:
		print(i)
		break


(n, k) = list(map(int, input().split()))
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = list(map(int, input().split()))
judge = 0
dic = {}
for i in range(n):
	if a[i] in dic:
		dic[a[i]] += b[i]
	else:
		dic[a[i]] = b[i]
dic = list(dic.items())
dic.sort()
for i in range(10 ** 9):
	if judge >= k:
		print(dic[i - 1][0])
		break
	else:
		judge += int(dic[i][1])


(N, K) = map(int, input().split())
AB = sorted((tuple(map(int, input().split())) for _ in range(N)))
for (a, b) in AB:
	if K <= b:
		print(a)
		break
	else:
		K -= b


(n, k) = map(int, input().split())
a = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
tmp = 0
for i in a:
	tmp += i[1]
	if tmp >= k:
		print(i[0])
		exit()


(N, K) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
for (A, B) in sorted(AB):
	K -= B
	if K <= 0:
		print(A)
		break


(N, K) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)])
tmp = 0
for (a, b) in AB:
	if tmp < K - b:
		tmp += b
	else:
		print(a)
		break


(N, K) = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]
lst.sort(key=lambda x: x[0])
s = 0
for i in range(N):
	s += lst[i][1]
	if s >= K:
		break
print(lst[i][0])


(N, K) = map(int, input().split())
c = [0] * (l := (10 ** 5 + 1))
s = 0
for i in range(N):
	(a, b) = map(int, input().split())
	c[a] += b
for i in range(l):
	s += c[i]
	if s >= K:
		print(i)
		break


(n, k) = map(int, input().split())
a = sorted([list(map(int, input().split())) for i in range(n)])
s = 0
for x in a:
	if k <= s + x[1]:
		print(x[0])
		break
	s += x[1]


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
ct = 0
for i in range(n):
	ct += ab[i][1]
	if ct >= k:
		print(ab[i][0])
		exit()


(n, k, *AB) = map(int, open(0).read().split())
(*AB,) = zip(AB[::2], AB[1::2])
AB.sort()
count = 0
for (a, b) in AB:
	count += b
	if count >= k:
		print(a)
		exit()


(N, K) = map(int, input().split())
l = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
c = 0
for i in l:
	c += i[1]
	if c >= K:
		print(i[0])
		break


import sys
input = sys.stdin.readline

def main():
	(n, k) = map(int, input().split())
	A = [0 for i in range(10 ** 5 + 1)]
	for i in range(n):
		(a, b) = map(int, input().split())
		A[a] += b
	i = 0
	sum = 0
	while sum < k:
		i += 1
		sum += A[i]
	print(i)
main()


(N, K) = map(int, input().split())
bucket = [0] * (10 ** 5 + 1)
for _ in range(N):
	(a, b) = map(int, input().split())
	bucket[a] += b
cnt = 0
for (i, c) in enumerate(bucket):
	if c == 0:
		continue
	cnt += c
	if cnt >= K:
		print(i)
		return


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
b = []
c = 0
for (i, j) in a:
	k -= j
	c = i
	if k <= 0:
		break
print(c)


(n, k) = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
num_sum = 0
for (a, b) in ab:
	num_sum += b
	if num_sum >= k:
		print(a)
		return


(n, k) = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
x.sort()
num = 0
for i in x:
	num += i[1]
	if num >= k:
		print(i[0])
		break


(N, K) = map(int, input().split())
ab = sorted((tuple(map(int, input().split())) for _ in range(N)))
x = K
for (a, b) in ab:
	if b >= x:
		print(a)
		exit()
	else:
		x -= b


(n, k) = map(int, input().split())
s = []
for i in range(n):
	(x, y) = map(int, input().split())
	s.append([x, y])
s.sort()
for i in range(n):
	k -= s[i][1]
	if k <= 0:
		print(s[i][0])
		break


(n, k, *x) = list(map(int, open(0).read().split()))
for (a, b) in sorted(zip(x[0::2], x[1::2])):
	k -= b
	if k < 1:
		print(a)
		break


def main():
	(N, K) = list(map(int, input().split()))
	lis = []
	for i in range(N):
		(a, b) = list(map(int, input().split()))
		lis.append((a, b))
	lis = sorted(lis)
	for i in range(N):
		K -= lis[i][1]
		if K <= 0:
			print(lis[i][0])
			break

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
info = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for (a, b) in info:
	cnt += b
	if cnt >= K:
		print(a)
		break


(n, k) = map(int, input().split())
for (s, t) in sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0]):
	if k > t:
		k -= t
	else:
		print(s)
		exit()


(n, k) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
a = sorted(a, key=lambda x: x[0])
x = 0
for i in a:
	x += i[1]
	if x >= k:
		break
print(i[0])


(n, k) = map(int, input().split())
x = sorted([list(map(int, input().split())) for i in range(n)])
for (i, j) in x:
	k -= j
	if k <= 0:
		print(i)
		exit()


from collections import Counter
(n, k) = map(int, input().split())
d = Counter()
for _ in range(n):
	(a, b) = map(int, input().split())
	d[a] += b
x = sorted(d.items(), key=lambda x: x[0])
cnt = 0
for (a, b) in x:
	cnt += b
	if cnt >= k:
		print(a)
		return


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
res = k
ab.sort()
for i in range(n):
	res -= ab[i][1]
	if res <= 0:
		print(ab[i][0])
		return


(n, k) = list(map(int, input().split()))
A = []
for _ in range(n):
	A.append(list(map(int, input().split())))
A.sort(key=lambda x: x[0])
cnt = 0
while k > 0:
	k -= A[cnt][1]
	cnt += 1
print(A[cnt - 1][0])


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()

def slv():
	cnt = 0
	for i in range(n):
		cnt += ab[i][1]
		if cnt >= k:
			return print(ab[i][0])
slv()


(n, k) = map(int, input().split())
l = [0] * 100001
for i in range(n):
	(a, b) = map(int, input().split())
	l[a] += b
x = 0
for i in range(100001):
	x += l[i]
	if x >= k:
		break
print(i)


(n, k) = map(int, input().split())
d = {}
for _ in range(n):
	(a, b) = map(int, input().split())
	if a in d.keys():
		d[a] += b
	else:
		d[a] = b
cnt = 0
sorted_d = sorted(d.items(), key=lambda x: x[0])
for (key, val) in sorted_d:
	cnt += val
	if k <= cnt:
		print(key)
		break


(n, k) = (int(i) for i in input().split())
a = [[int(i) for i in input().split()] for i in range(n)]
a.sort()
i = 0
ans = 0
while ans < k:
	ans += a[i][1]
	i += 1
print(a[i - 1][0])


(N, K) = list(map(int, input().split()))
A = []
for i in range(N):
	(a, b) = list(map(int, input().split()))
	A.append([a, b])
A.sort()
for i in range(N):
	K = K - A[i][1]
	if K <= 0:
		print(A[i][0])
		return


(n, k) = map(int, input().split())
q = []
for i in range(n):
	q.append(list(map(int, input().split())))
q = sorted(q, key=lambda x: x[0])
cnt = 0
i = 0
while cnt < k:
	(a, b) = q[i]
	cnt += b
	i += 1
print(a)


(n, k) = map(int, input().split())
query = sorted([tuple(map(int, input().split())) for _ in range(n)])
cnt = 0
i = 0
while cnt < k:
	(a, b) = query[i]
	cnt += b
	i += 1
print(a)


(n, k) = map(int, input().split())
for (a, b) in sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0]):
	if k > b:
		k -= b
	else:
		print(a)
		break


(N, K) = map(int, input().split())
L = []
S = 0
for i in range(N):
	L.append(list(map(int, input().split())))
L.sort()
for i in range(N):
	S += L[i][1]
	if S >= K:
		print(L[i][0])
		break


(N, K) = map(int, input().split())
nums = []
for _ in range(N):
	(a, b) = map(int, input().split())
	nums.append([a, b])
nums.sort()
S = 0
for i in range(N + 1):
	if S < K:
		S += nums[i][1]
	else:
		print(nums[i - 1][0])
		break


(n, k) = list(map(int, input().split()))
ar = {}
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if (a in ar) == True:
		ar[a] += b
	else:
		ar[a] = b
for i in sorted(ar.keys()):
	k -= ar[i]
	if k <= 0:
		print(i)
		break


(N, K) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])
for e in L:
	K -= e[1]
	if K <= 0:
		print(e[0])
		exit(0)


(N, K) = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(N)]
ab.sort()
check = 0
for (a, b) in ab:
	check += b
	if check >= K:
		print(a)
		break


(n, k, *ab) = map(int, open(0).read().split())
ab = [(ab[i * 2], ab[i * 2 + 1]) for i in range(n)]
ab.sort(key=lambda x: x[0])
c = 0
for (i, j) in ab:
	c += j
	if c >= k:
		break
print(i)


f = lambda : map(int, input().split())
(N, K) = f()
for (a, b) in sorted(([*f()] for _ in [0] * N)):
	K -= b
	if K < 1:
		print(a)
		return


(n, k) = list(map(int, input().split()))
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
	(a[i], b[i]) = list(map(int, input().split()))
d = {}
for i in range(n):
	if a[i] not in d:
		d[a[i]] = b[i]
	else:
		d[a[i]] += b[i]
d = sorted(list(d.items()), key=lambda x: x[0])
tmp = 0
for i in range(len(d)):
	tmp += d[i][1]
	if tmp >= k:
		print(d[i][0])
		return


(N, K) = list(map(int, input().split()))
ab = [[0, 0]] * N
for i in range(N):
	(_a, _b) = list(map(int, input().split()))
	ab[i] = [_a, _b]
ab.sort(key=lambda x: x[0])
j = 0
index = 0
while j < K:
	j += ab[index][1]
	if j < K:
		index += 1
print(ab[index][0])


(N, K) = map(int, input().split())
S = sorted([list(map(int, input().split())) for i in range(N)])
count = 0
for i in S:
	count = count + i[1]
	if count >= K:
		print(i[0])
		break


from collections import defaultdict
(N, K) = list(map(int, input().split()))
N_List = defaultdict(int)
for i in range(N):
	(Num, Cnt) = list(map(int, input().split()))
	N_List[Num] += Cnt
N_List = sorted(list(N_List.items()), key=lambda x: x[0])
ans = 0
for (Key, Value) in N_List:
	ans += Value
	if ans >= K:
		print(Key)
		break


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
for u in ab:
	(a, b) = u
	k -= b
	if k <= 0:
		print(a)
		break


(n, k) = map(int, input().split())
ls = [[int(_) for _ in input().split()] for _ in range(n)]
ls.sort()
ln = 0
for i in range(n):
	ln += ls[i][1]
	if ln >= k:
		print(ls[i][0])
		break


(n, k) = map(int, input().split())
a = sorted([list(map(int, input().split())) for _ in range(n)])
c = 0
for i in a:
	c += i[1]
	if k <= c:
		print(i[0])
		exit()


(N, K) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A = sorted(A, key=lambda x: x[0])
cnt = 0
i = 0
while K > cnt:
	cnt += A[i][1]
	i += 1
print(A[i - 1][0])


(n, k) = map(int, input().split())
x = []
for i in range(n):
	(a, b) = map(int, input().split())
	x.append([a, b])
x.sort()
c = 0
for (i, j) in x:
	c += j
	if k <= c:
		print(i)
		exit()
print(j)


(N, K, *l) = list(map(int, open(0).read().split()))
for (a, b) in sorted(zip(l[::2], l[1::2])):
	if (K := (K - b)) < 1:
		break
print(a)


(N, K) = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort()
t = 0
for (a, b) in ab:
	t += b
	if t >= K:
		print(a)
		break


(n, k) = map(int, input().split())
ab = []
for _ in range(n):
	(a, b) = map(int, input().split())
	ab.append((a, b))
ab.sort()
for (i, j) in ab:
	k -= j
	if k <= 0:
		print(i)
		exit()


def main():
	(n, k) = list(map(int, input().split()))
	arr = sorted([list(map(int, input().split())) for i in range(n)])
	for ab in arr:
		k -= ab[1]
		if k <= 0:
			ans = ab[0]
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


xx = []
(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
xx = sorted(ab, key=lambda x: x[0])
ans = 0
for i in range(n):
	ans += xx[i][1]
	if ans >= k:
		print(xx[i][0])
		break


(n, k) = map(int, input().split())
s = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (a, b) in s:
	ans += b
	if k <= ans:
		print(a)
		exit()


(N, K) = map(int, input().split())
lis = []
for _ in range(N):
	(a, b) = map(int, input().split())
	lis.append((a, b))
lis = sorted(lis, reverse=False)
cnt = 0
num = 0
for (a, b) in lis:
	cnt += b
	num = a
	if cnt >= K:
		break
print(num)


(n, k) = map(int, input().split())
c = [0] * 100000
for i in range(n):
	(a, b) = map(int, input().split())
	c[a - 1] += b
i = 0
count = 0
while count < k:
	count += c[i]
	i += 1
print(i)


f = lambda : map(int, input().split())
(n, k) = f()
d = {}
for i in range(n):
	(a, b) = f()
	d[a] = d.get(a, 0) + b
c = 0
for (a, b) in sorted(d.items()):
	c += b
	if c >= k:
		print(a)
		break


(N, K) = map(int, input().split())
A = sorted([list(map(int, input().split())) for n in range(N)])
c = 0
for n in range(N):
	c += A[n][1]
	if K <= c:
		print(A[n][0])
		break


(n, k) = map(int, input().split())
A = []
for _ in range(n):
	A.append(list(map(int, input().split())))
A.sort()
cnt = A[0][1]
i = 0
while cnt < k:
	i += 1
	cnt += A[i][1]
print(A[i][0])


(N, K) = list(map(int, input().split()))
A = list()
for i in range(N):
	(a, b) = list(map(int, input().split()))
	A.append((a, b))
A.sort(key=lambda x: x[0])
tmp = 0
for i in range(N):
	(a, b) = A[i]
	tmp += b
	if tmp >= K:
		print(a)
		break


(n, k) = map(int, input().split())
d = [0] * (10 ** 5 + 1)
for i in range(n):
	(a, b) = map(int, input().split())
	d[a] += b
for i in range(10 ** 5 + 1):
	if d[i] >= k:
		print(i)
		break
	else:
		k -= d[i]


(N, K) = map(int, input().split())
c = sorted([list(map(int, input().split())) for _ in range(N)])
for (a, b) in c:
	K -= b
	if K <= 0:
		print(a)
		exit()


(N, K) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(N)]
l.sort(key=lambda x: x[0])
ans = 0
for i in l:
	if K == 0:
		break
	K -= min(K, i[1])
	ans = i[0]
print(ans)


(N, K) = map(int, input().split())
ans = []
for i in range(N):
	ab = list(map(int, input().split()))
	ans.append(ab)
ans.sort()
l = 0
for i in range(N):
	l += ans[i][1]
	if l >= K:
		s = i
		break
print(ans[s][0])


(n, k) = map(int, input().split())
a = []
for i in range(n):
	A = list(map(int, input().split()))
	a.append(A)
a = sorted(a, key=lambda x: x[0])
b = 0
for i in range(n):
	b += a[i][1]
	if b >= k:
		print(a[i][0])
		return


(n, k) = map(int, input().split())
ref = []
for i in range(n):
	(a, b) = map(int, input().split())
	ref.append([a, b])
ref.sort()
for (x, y) in ref:
	k -= y
	if k <= 0:
		print(x)
		exit()


(n, k) = map(int, input().split())
hoge = [0] * 100001
for i in range(n):
	(a, b) = map(int, input().split())
	hoge[a] += b
for i in range(100001):
	k -= hoge[i]
	if k <= 0:
		print(i)
		exit()


(n, k) = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in range(n)])
cou = 0
for r in l:
	(a, b) = (r[0], r[1])
	cou += b
	if cou >= k:
		print(a)
		break


(n, k) = map(int, input().split())
ans = [0] * (10 ** 5 + 1)
for i in range(n):
	(a, b) = map(int, input().split())
	ans[a] += b
for i in range(len(ans)):
	k -= ans[i]
	if k <= 0:
		print(i)
		break


(N, K) = map(int, input().split())
d = {}
for i in range(N):
	(a, b) = map(int, input().split())
	d[a] = d.get(a, 0) + b
cnt = 0
for k in sorted(d.keys()):
	cnt += d[k]
	if cnt >= K:
		print(k)
		break


(n, k) = map(int, input().split())
S = set()
D = dict()
for _ in range(n):
	(a, b) = map(int, input().split())
	if a in S:
		D[a] += b
	else:
		S.add(a)
		D[a] = b
L = sorted(S)
cnt = 0
for l in L:
	cnt += D[l]
	if cnt >= k:
		print(l)
		break


(N, M) = map(int, input().split())
inp = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
for (i, j) in inp:
	if M > j:
		M -= j
	else:
		print(i)
		break


(n, k) = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in range(n)])
x = 0
for i in range(n):
	x += l[i][1]
	if x >= k:
		print(l[i][0])
		break


(N, K) = map(int, input().split())
li = sorted([tuple(map(int, input().split())) for _ in range(N)])
cnt = 0
for (a, b) in li:
	cnt += b
	if cnt >= K:
		print(a)
		break


(N, K) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
sums = 0
for i in range(N):
	sums += A[i][1]
	if sums >= K:
		print(A[i][0])
		break


(n, k) = [int(x) for x in input().split()]
an = [list(map(int, input().split())) for _ in range(n)]
for (a, b) in sorted(an):
	k -= b
	if k < 1:
		print(a)
		exit(0)


(n, k) = [int(i) for i in input().split()]

class Number:

	def __init__(self, number, times):
		self.number = number
		self.times = times

	def __eq__(self, other):
		if self.number == other.number:
			return True
		return False

	def __le__(self, other):
		if self.number <= other.number:
			return True
		return False

	def __lt__(self, other):
		if self.number < other.number:
			return True
		return False

	def __ge__(self, other):
		if self.number >= other.number:
			return True
		return False

	def __gt__(self, other):
		if self.number > other.number:
			return True
		return False
number_list = []
for i in range(n):
	(number, times) = [int(i) for i in input().split()]
	number_list.append(Number(number, times))
number_list.sort()

def get(number_list, k):
	i = 0
	while True:
		taishou = number_list[i]
		k = k - taishou.times
		if k <= 0:
			return taishou.number
		else:
			i += 1
print(get(number_list, k))


(n, k) = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
arr.sort()
for a in arr:
	k -= a[1]
	if k <= 0:
		print(a[0])
		exit()


from sys import stdin
input = stdin.readline
from itertools import accumulate
from bisect import bisect_left
(N, K) = map(int, input().split())
memo = [0] * 100010
for _ in range(N):
	(a, b) = map(int, input().split())
	memo[a] += b
print(bisect_left(list(accumulate(memo)), K))


(n, k) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
l.sort()
i = 0
ans = 0
while k > 0:
	k = k - l[i][1]
	ans = l[i][0]
	i = i + 1
print(ans)


def main():
	(N, K) = list(map(int, input().split()))
	box = []
	for _ in range(N):
		ab = list(map(int, input().split()))
		box.append(ab)
	box.sort(key=lambda x: x[0])
	ans = 0
	for b in box:
		if ans + b[1] < K:
			ans += b[1]
		else:
			print(b[0])
			return

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
L = []
for i in range(N):
	(a, b) = map(int, input().split())
	L.append([a, b])
L = sorted(L)
for i in range(N):
	if L[i][1] < K:
		K -= L[i][1]
	else:
		print(L[i][0])
		exit()


(N, K) = map(int, input().split())
num = [0] * (10 ** 5 + 1)
for i in range(N):
	(a, b) = map(int, input().split())
	num[a] += b
tmp = 0
for i in range(10 ** 5 + 1):
	tmp += num[i]
	if tmp >= K:
		print(i)
		break


(N, K, *l) = map(int, open((c := 0)).read().split())
d = {}
for (a, b) in zip(l[::2], l[1::2]):
	d[a] = d.get(a, 0) + b
for k in sorted(d.keys()):
	if (c := (c + d[k])) >= K:
		break
print(k)


(N, K) = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(N)]
l.sort(key=lambda x: x[0])
cnt = 0
for x in l:
	cnt += x[1]
	if cnt >= K:
		print(x[0])
		break


(n, k) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
cnt = 0
for (i, j) in AB:
	cnt += j
	if k <= cnt:
		print(i)
		exit()


(n, k) = list(map(int, input().split()))
bucket = [0] * 10 ** 5
for i in range(n):
	(a, b) = list(map(int, input().split()))
	bucket[a - 1] += b
sum_b = 0
for i in range(len(bucket)):
	sum_b += bucket[i]
	if sum_b >= k:
		print(i + 1)
		break


(n, k) = map(int, input().split())
num = sorted([list(map(int, input().split())) for _ in range(n)])
cnt = 0
for (a, b) in num:
	cnt += b
	if cnt >= k:
		print(a)
		break


(N, K) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(N)])
s = 0
for (a, b) in ab:
	s += b
	if s >= K:
		print(a)
		break


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
cnt = 0
for (x, y) in a:
	cnt += y
	if cnt >= k:
		print(x)
		exit()


import sys
stdin = sys.stdin

def ns():
	return stdin.readline().rstrip()

def ni():
	return int(stdin.readline().rstrip())

def nm():
	return list(map(int, stdin.readline().split()))

def nl():
	return list(map(int, stdin.readline().split()))

def main():
	(n, k) = nm()
	A = [0] * (10 ** 5 + 1)
	for i in range(n):
		(a, b) = nm()
		A[a] += b
	sum_num = 0
	for (i, a) in enumerate(A):
		sum_num += a
		if sum_num >= k:
			print(i)
			return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
l = [[*map(int, input().split())] for i in range(n)]
l.sort(key=lambda x: x[0])
for (i, j) in l:
	k -= j
	if k <= 0:
		print(i)
		break


(n, k) = map(int, input().split())
s = sorted([[int(i) for i in input().split()] for l in range(n)])
c = 0
for x in s:
	c += x[1]
	if c >= k:
		print(x[0])
		break


(n, k) = map(int, input().split())
al = [0] * (10 ** 5 + 1)
for _ in range(n):
	(a, b) = map(int, input().split())
	al[a] += b
cnt = 0
i = 0
while cnt < k:
	cnt += al[i]
	i += 1
print(i - 1)


(n, k) = map(int, input().split())
(num, count) = ([0] * (10 ** 5 + 1), 0)
for _ in range(n):
	(a, b) = map(int, input().split())
	num[a] += b
for i in range(len(num)):
	count += num[i]
	if count >= k:
		print(i)
		break


(N, K) = map(int, input().split())
C = [0] * (10 ** 5 + 1)
for i in range(N):
	(a, b) = map(int, input().split())
	C[a] += b
cnt = 0
l = 0
while cnt < K:
	l += 1
	cnt += C[l]
print(l)


(N, K) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
count = 0
AB.sort()
for (a, b) in AB:
	count += b
	if count >= K:
		print(a)
		exit()


(n, k) = [int(x) for x in input().split()]
a = []
for i in range(n):
	a.append([int(x) for x in input().split()])
a.sort()
c = 0
while k > 0:
	k -= a[c][1]
	c += 1
print(a[c - 1][0])


(N, K) = map(int, input().split())
cnt = 0
P = []
for i in range(N):
	(a, b) = map(int, input().split())
	P.append((a, b))
P = sorted(P)
for i in range(N):
	cnt += P[i][1]
	if cnt >= K:
		print(P[i][0])
		break


(n, k) = map(int, input().split())
B = [0] * 100001
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	B[a] += b
for j in range(1, 10 ** 5 + 1):
	k -= B[j]
	if k <= 0:
		print(j)
		break


(N, K) = map(int, input().split())
src = [tuple(map(int, input().split())) for i in range(N)]
s = 0
for (a, b) in sorted(src):
	s += b
	if s >= K:
		print(a)
		break


(n, k) = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
cnt = 0
for (i, j) in ab:
	cnt += j
	if cnt >= k:
		ans = i
		print(ans)
		exit()


(n, k) = list(map(int, input().split()))
dic = {}
for i in range(n):
	(a, b) = list(map(int, input().split()))
	dic[a] = dic.get(a, 0) + b
l = sorted(dic.items())
for (a, b) in l:
	if k <= b:
		ans = a
		break
	k -= b
print(ans)


(N, K) = map(int, input().split())
X = sorted([[int(a) for a in input().split()] for _ in range(N)])
i = 0
K -= X[0][1]
while K > 0:
	i += 1
	K -= X[i][1]
print(X[i][0])


from collections import defaultdict
(n, k) = map(int, input().split())
ans = 0
al = []
d = defaultdict(int)
for i in range(n):
	(a, b) = map(int, input().split())
	al.append(a)
	d[a] += b
al = list(set(al))
al.sort()
for i in al:
	if k > d[i]:
		k -= d[i]
	else:
		print(i)
		break


((n, k), *q) = [[*map(int, i.split())] for i in open(0)]
q.sort()
for (a, b) in q:
	k -= b
	if k <= 0:
		print(a)
		break


(N, K) = map(int, input().split())
li = sorted([list(map(int, input().split())) for _ in range(N)])
for l in li:
	K -= l[1]
	if K <= 0:
		print(l[0])
		exit()


(n, k) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(n)])
s = 0
for i in range(n):
	s += L[i][1]
	if s >= k:
		print(L[i][0])
		exit()


(n, k) = map(int, input().split())
l = []
for i in range(n):
	(x, y) = map(int, input().split())
	l.append([x, y])
l.sort()
sum = l[0][1]
i = 0
while sum < k:
	i += 1
	sum += l[i][1]
print(l[i][0])


(n, k) = list(map(int, input().split()))
li = []
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	li.append([a, b])
li.sort()
for (a, b) in li:
	k -= b
	if k <= 0:
		print(a)
		break


(N, K) = map(int, input().split())
ab = [[int(x) for x in input().split()] for _ in range(N)]
ab.sort()
cnt = 0
for (a, b) in ab:
	cnt += b
	if cnt >= K:
		print(a)
		break


(n, k) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
i = 0
c = ab[0][1]
while c < k:
	i += 1
	c += ab[i][1]
print(ab[i][0])


(n, k) = map(int, input().split())
N = [0] * (10 ** 5 + 1)
for i in range(n):
	(a, b) = map(int, input().split())
	N[a] += b
for i in range(10 ** 5 + 1):
	k -= N[i]
	if k <= 0:
		print(i)
		exit()


(N, K, *A) = map(int, open(0).read().split())
A = sorted(zip(A[::2], A[1::2]), key=lambda x: x[0])
for (a, b) in A:
	if K <= b:
		print(a)
		break
	K -= b


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '3 4\n1 1\n2 2\n3 3'
		output = '3'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '10 500000\n1 100000\n1 100000\n1 100000\n1 100000\n1 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000'
		output = '1'
		self.assertIO(input, output)

def resolve():
	(N, K) = list(map(int, input().split()))
	D = [list(map(int, input().split())) for _ in range(N)]
	D.sort()
	t = 0
	for d in D:
		t += d[1]
		if t >= K:
			print(d[0])
			break

def __starting_point():
	resolve()
__starting_point()


(n, k) = list(map(int, input().split()))
sum_b = 0
ab_list = []
for i in range(n):
	ab_list.append(list(map(int, input().split())))
ab_list.sort()
for i in range(n):
	(a, b) = ab_list[i]
	sum_b += b
	if sum_b >= k:
		print(a)
		break


(N, K) = list(map(int, input().split()))
cnt = 0
ls = []
for i in range(N):
	ls.append(list(map(int, input().split())))
ls.sort(key=lambda x: x[0])
for (a, b) in ls:
	cnt += b
	if cnt >= K:
		break
print(a)


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x: x[0])
(ans, i) = (0, 0)
t = 0
while ans < k:
	ans += a[i][1]
	t = a[i][0]
	i += 1
print(t)


ma = lambda : map(int, input().split())
(n, k) = ma()
ab = []
for i in range(n):
	ab.append(list(ma()))
ab.sort()
c = 0
for (a, b) in ab:
	c += b
	if c >= k:
		print(a)
		break


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	(n, k) = inl()
	v = []
	for i in range(n):
		(a, b) = inl()
		v.append((a, b))
	v.sort(reverse=True)
	c = k - 1
	while v:
		(a, b) = v.pop()
		if b > c:
			return a
		c -= b
print(solve())


temp = input().split()
N = int(temp[0])
K = int(temp[1])
ab = [[int(j) for j in input().split()] for i in range(N)]
ab.sort()
while ab[0][1] < K:
	K -= ab[0][1]
	del ab[0]
print(ab[0][0])


(N, K, *AB) = map(int, open(0).read().split())
li = [(a, b) for (a, b) in zip(*[iter(AB)] * 2)]
li.sort()
for (a, b) in li:
	if K > b:
		K -= b
	else:
		print(a)
		break


(n, k) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
l.sort()
ct = 0
for i in range(n):
	ct += l[i][1]
	if ct >= k:
		print(l[i][0])
		break


(n, k) = map(int, input().split())
lst = sorted([list(map(int, input().split())) for _ in range(n)])
cnt = 0
sm = 0
for i in range(n):
	if sm < k:
		cnt += 1
	sm += lst[i][1]
print(lst[cnt - 1][0])


import bisect
(n, k) = list(map(int, input().split()))
hairetu = [0] * 100001
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	hairetu[a] += b
ruiseki = [0] * 100001
for i in range(1, 100001):
	ruiseki[i] = ruiseki[i - 1] + hairetu[i]
print(bisect.bisect_left(ruiseki, k))


(N, K) = map(int, input().split())
temp = []
(c, t) = (K, -1)
for i in range(N):
	temp.append(list(map(int, input().split())))
temp.sort()
while c > 0:
	t += 1
	c -= temp[t][1]
print(temp[t][0])


(n, m) = map(int, input().split())
t = sorted([list(map(int, input().split())) for i in range(n)])
s = 0
for j in t:
	if s < m <= s + j[1]:
		print(j[0])
		break
	s = s + j[1]


(n, k) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[0])
tmp = 0
for (a, b) in ab:
	tmp += b
	if tmp >= k:
		print(a)
		exit()


def main2():
	(N, K) = map(int, input().split())
	limit = 10 ** 5
	ins = [0 for _ in range(limit + 1)]
	for _ in range(N):
		(a, b) = map(int, input().split())
		ins[a] += b
	c = 0
	for i in range(1, limit + 1):
		c += ins[i]
		if c >= K:
			print(i)
			return

def __starting_point():
	main2()
__starting_point()


(N, K) = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
l = 0
for (a, b) in AB:
	l += b
	if l >= K:
		print(a)
		exit()


def main():
	(n, k) = map(int, input().split())
	ab = [list(map(int, input().split())) for _ in range(n)]
	ab.sort()
	i = 0
	while k > 0:
		k -= ab[i][1]
		i += 1
	else:
		print(ab[i - 1][0])
main()


l = [*map(int, open((c := 0)).read().split())]
for (a, b) in sorted(zip(l[2::2], l[3::2])):
	if (c := (c + b)) >= l[1]:
		break
print(a)


import heapq
(n, k) = map(int, input().split())
q = []
for _ in range(n):
	(a, b) = map(int, input().split())
	heapq.heappush(q, (a, b))
while k > 0:
	(a, b) = heapq.heappop(q)
	k -= b
print(a)


f = lambda : map(int, input().split())
(n, k) = f()
c = 0
for (a, b) in sorted((list(f()) for _ in range(n))):
	c += b
	if c >= k:
		print(a)
		break


(n, k) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
A.sort()
i = -1
count = 0
ans = 0
while count < k:
	i += 1
	ans = A[i][0]
	count += A[i][1]
print(ans)


(N, K) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
s = 0
for (a, b) in AB:
	s += b
	if s >= K:
		ans = a
		break
print(ans)


(n, k) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
l.sort()
count = 0
for (i, j) in l:
	if j < k:
		k -= j
	else:
		print(i)
		exit()


from collections import defaultdict
(N, K, *ab) = list(map(int, open(0).read().split()))
cnt = defaultdict(int)
for (a, b) in zip(*[iter(ab)] * 2):
	cnt[a] += b
li = [(k, v) for (k, v) in list(cnt.items())]
li.sort()
for (a, b) in li:
	if K - b > 0:
		K -= b
	else:
		print(a)
		break


(N, K) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
	cnt += L[i][1]
	if cnt >= K:
		ans = L[i][0]
		break
print(ans)


(n, k) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort(key=lambda x: x[0])
count = 0
for (i, j) in a:
	count += j
	if k <= count:
		print(i)
		exit()


(n, k) = map(int, input().split())
l = [0] * 10000001
for _ in range(n):
	(a, b) = map(int, input().split())
	l[a] += b
for i in range(1, 10000001):
	if k <= l[i]:
		print(i)
		break
	k -= l[i]


I = lambda : list(map(int, input().split()))
(N, K) = I()
AB = sorted([I() for _ in [0] * N])
s = 0
for (a, b) in AB:
	if s + b >= K:
		print(a)
		break
	s += b


(n, k) = map(int, input().split())
a = sorted([list(map(int, input().split())) for i in range(n)])
i = 0
while True:
	if k - a[i][1] > 0:
		k -= a[i][1]
	else:
		print(a[i][0])
		exit()
	i += 1


(N, K) = list(map(int, input().split()))
ab = [[0, 0]] * N
for i in range(N):
	(_a, _b) = list(map(int, input().split()))
	ab[i] = [_a, _b]
ab.sort(key=lambda x: x[0])
total = 0
for pair in ab:
	total += pair[1]
	if total >= K:
		print(pair[0])
		break


f = lambda l: map(int, l.split())
(N, K) = f((p := input)())
c = [0] * (l := (10 ** 5 + 1))
s = 0
for i in (r := range)(N):
	(a, b) = f(p())
	c[a] += b
for i in r(l):
	s += c[i]
	if s >= K:
		print(i)
		break


(n, k) = map(int, input().split())
d = [0] * 100001
for i in range(n):
	(a, b) = map(int, input().split())
	d[a] += b
cnt = 0
for i in range(100001):
	if cnt + d[i] >= k:
		print(i)
		quit()
	cnt += d[i]


(a, b) = map(int, input().split())
l = sorted((tuple(map(int, input().split())) for _ in range(a)))
s = 0
for i in l:
	s += i[1]
	if s >= b:
		print(i[0])
		break


(n, k) = map(int, input().split())
l = []
for _ in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
l.sort()
cnt = 0
for (a, b) in l:
	cnt += b
	if k <= cnt:
		print(a)
		break


(n, k) = map(int, input().split())
l = []
for _ in [0] * n:
	l += [list(map(int, input().split()))]
l.sort()
s = 0
i = -1
while s < k:
	i += 1
	s += l[i][1]
print(l[i][0])


(n, k) = map(int, input().split())
arr = [0] * 100100
for i in range(n):
	(a, b) = map(int, input().split())
	arr[a] += b
cur = 0
for i in range(100100):
	cur += arr[i]
	if cur >= k:
		print(i)
		break


from collections import defaultdict as dd
from itertools import count
(N, K) = map(int, input().split())
Cnt = dd(lambda : 0)
for _ in range(N):
	(a, b) = map(int, input().split())
	Cnt[a] += b
num = 0
for i in count(1, 1):
	num += Cnt[i]
	if num >= K:
		print(i)
		break


(N, K) = map(int, input().split())
a = []
b = []
Sum = 0
for i in range(N):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
s = [*range(len(a))]
sort_s = sorted(s, key=lambda i: a[i])
sort_a = [a[i] for i in sort_s]
sort_b = [b[i] for i in sort_s]
for i in range(N):
	Sum += sort_b[i]
	if Sum >= K:
		print(sort_a[i])
		break


L = lambda : list(map(int, input().split()))
(n, k) = L()
for (a, b) in sorted([L() for _ in range(n)]):
	k -= b
	if k <= 0:
		print(a)
		exit()


(n, k) = map(int, input().split(' '))
a = sorted([list(map(int, input().split(' '))) for i in range(n)])
count = 0
for (x, y) in a:
	count += y
	if k <= count:
		print(x)
		break
else:
	print('None')


(N, K) = list(map(int, input().split()))
memory = {}
S = []
for i in range(N):
	(a, b) = list(map(int, input().split()))
	try:
		memory[a] += b
	except KeyError:
		memory[a] = b
A = sorted(list(memory.keys()))
for a in A:
	if not S:
		S.append(memory[a])
	else:
		S.append(S[-1] + memory[a])
for i in range(N):
	if S[i] >= K:
		print(A[i])
		break


(N, K) = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(N)])
for (a, b) in ab_list:
	if b >= K:
		print(a)
		exit()
	else:
		K -= b


(N, K) = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort()
count = 0
i = 0
while count < K:
	count += AB[i][1]
	i += 1
print(AB[i - 1][0])