Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.
There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.
What is the minimum amount of money with which he can buy M cans of energy drinks?
It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N, M \leq 10^5
 - 1 \leq A_i \leq 10^9
 - 1 \leq B_i \leq 10^5
 - B_1 + ... + B_N \geq M

-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

-----Output-----
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

-----Sample Input-----
2 5
4 9
2 4

-----Sample Output-----
12

With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.

Difficulty: EASY

Solutions:
(n, m) = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ab_sorted = sorted(ab, key=lambda x: (x[0], -x[1]))
num = 0
amount_of_money = 0
for i in range(n):
	buy = min(ab_sorted[i][1], m - num)
	num += buy
	amount_of_money += ab_sorted[i][0] * buy
	if num >= m:
		print(amount_of_money)
		return


(N, M) = map(int, input().split())
AB = []
p = 0
for n in range(N):
	AB.append(list(map(int, input().split())))
AB.sort()
for (s, b) in AB:
	p += s * min(M, b)
	M -= min(M, b)
print(p)


(N, M) = map(int, input().split())
tmp = []
ans = 0
for _ in range(N):
	tmp.append(list(map(int, input().split())))
tmp.sort()
i = 0
while M > 0:
	ans += tmp[i][0] * min(M, tmp[i][1])
	M -= tmp[i][1]
	i += 1
print(ans)


f = lambda : [*map(int, input().split())]
(n, m) = f()
c = 0
for (a, b) in sorted((f() for _ in range(n))):
	t = min(b, m)
	c += a * t
	m -= t
print(c)


(n, m) = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(n)])
(i, ans) = (0, 0)
while ab[i][1] < m:
	m -= ab[i][1]
	ans += ab[i][1] * ab[i][0]
	i += 1
ans += ab[i][0] * m
print(ans)


(n, m) = map(int, input().split())
ll = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (p, c) in ll:
	ans += p * min(m, c)
	m -= c
	if m < 1:
		break
print(ans)


(N, M) = map(int, input().split())
cost = 0
for (A, B) in sorted((tuple(map(int, input().split())) for i in range(N)), key=lambda p: p[0]):
	bought = min(M, B)
	cost += A * bought
	M -= bought
print(cost)


(n, m) = map(int, input().split())
P = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 0
for (x, y) in P:
	q = min(m, y)
	ans += x * q
	m -= q
	if m == 0:
		print(ans)
		exit()


import sys
pin = sys.stdin.readline

def main():
	(N, M) = map(int, pin().split())
	d = [list(map(int, pin().split())) for _ in [0] * N]
	d.sort()
	cnt = 0
	ans = 0
	for i in d:
		if M <= cnt + i[1]:
			ans += i[0] * (M - cnt)
			print(ans)
			return
		cnt += i[1]
		ans += i[0] * i[1]
	print(ans)
	return
main()


(N, M) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
idx = 0
while M:
	b = min(M, AB[idx][1])
	ans += AB[idx][0] * b
	M -= b
	idx += 1
print(ans)


(N, M) = map(int, input().split())
AB = [0] * N
for i in range(N):
	AB[i] = list(map(int, input().split()))
AB = sorted(AB, key=lambda x: x[0])
ans = 0
for i in range(N):
	if M > AB[i][1]:
		M -= AB[i][1]
		ans += AB[i][0] * AB[i][1]
	else:
		ans += AB[i][0] * M
		M = 0
	if M == 0:
		break
print(ans)


(N, M) = [int(v) for v in input().split(' ')]
d = []
for i in range(N):
	d.append([int(v) for v in input().split(' ')])
total = 0
for (v, n) in sorted(d):
	if M > n:
		total += v * n
		M -= n
	else:
		total += v * M
		break
print(total)


(n, m) = list(map(int, input().split()))
x = [list(map(int, input().split())) for l in range(n)]
x = sorted(x)
count = m
p = 0
for i in x:
	if count >= i[1]:
		count -= i[1]
		p += i[0] * i[1]
	elif count == 0:
		break
	else:
		p += i[0] * count
		count = 0
print(p)


(n, m) = map(int, input().split())
a = sorted([list(map(int, input().split())) for _ in range(n)])
pay = 0
i = 0
while m > 0:
	p = min(m, a[i][1])
	m -= p
	pay += p * a[i][0]
	i += 1
print(pay)


(n, m) = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for j in range(n)]
ab.sort()
money = 0
for (a, b) in ab:
	if b < m:
		money += a * b
		m -= b
	else:
		money += a * m
		break
print(money)


(N, M) = map(int, input().split())
list = []
for _ in range(N):
	(a, b) = map(int, input().split())
	list.append([a, b])
list.sort()
ans = 0
for (a, b) in list:
	ans += min(b, M) * a
	M = max(0, M - b)
print(ans)


(n, m) = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (a, b) in l:
	if b < m:
		ans += a * b
		m -= b
	else:
		ans += a * m
		break
print(ans)


(n, m) = list(map(int, input().split()))
stores = [list(map(int, input().split())) for _ in range(n)]
sorted_sotres = sorted(stores, key=lambda x: x[0])
total = 0
ans = 0
for (cost, number) in sorted_sotres:
	if number > m:
		ans += cost * m
		break
	elif number == m:
		ans += cost * number
		break
	else:
		ans += cost * number
	m -= number
print(ans)


(N, M) = map(int, input().split())
S = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
ans = 0
for (a, b) in S:
	if M <= 0:
		break
	x = min(M, b)
	ans += a * x
	M -= x
print(ans)


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
l.sort()
ans = 0
for (a, b) in l:
	ans += min(b, m) * a
	m = max(0, m - b)
print(ans)


(N, m) = map(int, input().split())
A = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
	cnt += A[i][0] * min(m, A[i][1])
	m -= min(m, A[i][1])
print(cnt)


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
a = [''] * n
for ii in range(n):
	a[ii] = list(map(int, input().split()))
a.sort()
r = 0
for ii in range(n):
	if a[ii][1] >= m:
		r += a[ii][0] * m
		print(r)
		return
	else:
		r += a[ii][0] * a[ii][1]
		m -= a[ii][1]


(n, m) = [int(x) for x in input().split()]
temp_list = sorted([[int(x) for x in input().split()] for _ in range(n)])
ans = 0
for (a, b) in temp_list:
	ans += a * min(b, m)
	m -= b
	if m <= 0:
		break
print(ans)


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
A.sort()
ans = 0
cnt = 0
for a in A:
	tmp = min(m - cnt, a[1])
	ans += tmp * a[0]
	cnt += tmp
	if cnt >= m:
		break
print(ans)


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: x[0])
ans = 0
for i in range(n):
	(s, t) = l[i]
	if m - t <= 0:
		ans += s * m
		break
	else:
		m -= t
		ans += s * t
print(ans)


(n, m) = list(map(int, input().split()))
C = {}
S1 = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	S1.append(a)
	if a in C:
		C[a] += b
	else:
		C[a] = b
S = list(set(S1))
S.sort()
ans = 0
for s in S:
	if m < C[s]:
		ans += m * s
		break
	else:
		ans += C[s] * s
		m -= C[s]
print(ans)


(N, M) = map(int, input().split())
info_lst = []
for _ in range(N):
	(a, b) = map(int, input().split())
	info_lst.append((a, b))
cost = 0
for (a, b) in sorted(info_lst):
	cost += a * min(b, M)
	M -= b
	if M <= 0:
		break
print(cost)


(N, M) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])
i = 0
n = 0
m = 0
while n < M:
	n += L[i][1]
	m += L[i][0] * L[i][1]
	i += 1
print(m + (M - n) * L[i - 1][0])


(n, m) = list(map(int, input().split()))
a = sorted([list(map(int, input().split())) for i in range(n)])
(cnt, ans, j) = (0, 0, 0)
while cnt < m:
	cnt += a[j][1]
	ans += a[j][0] * a[j][1]
	j += 1
print(ans - (cnt - m) * a[j - 1][0])


(n, m) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for i in ab:
	t = min(m, i[1])
	ans += i[0] * t
	m -= t
print(ans)


(N, M) = list(map(int, input().split()))
A = dict()
ans = 0
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
for i in range(N):
	if M > A[i][1]:
		M -= A[i][1]
		ans += A[i][0] * A[i][1]
	else:
		ans += A[i][0] * M
		break
print(ans)


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(n)]
sum = 0
mr = 0
ks = sorted(k)
for i in range(n):
	if ks[i][1] < m - mr:
		sum += ks[i][0] * ks[i][1]
		mr += ks[i][1]
	else:
		sum += ks[i][0] * (m - mr)
		break
print(sum)


(N, M) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab)
SUM = 0
for i in range(N):
	(a, b) = ab[i]
	x = min(M, b)
	SUM += a * x
	M -= x
	if M == 0:
		break
print(SUM)


I = lambda : list(map(int, input().split()))
(n, m) = I()
c = 0
for (a, b) in sorted((I() for _ in [0] * n)):
	c += a * min(m, b)
	m = max(0, m - b)
print(c)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])
ans = 0
count = 0
for i in range(N):
	(a, b) = AB[i]
	if M - count <= b:
		c = M - count
		count += c
		ans += a * c
		break
	count += b
	ans += a * b
print(ans)


(N, M) = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
cost = 0
cnt = 0
i = 0
while cnt < M:
	(a, b) = AB[i]
	if M - cnt <= b:
		cost += a * (M - cnt)
		cnt = M
		break
	cost += a * b
	cnt += b
	i += 1
ans = cost
print(ans)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB)
sum = 0
answer = 0
i = 0
while sum < M:
	plus = min(AB[i][1], M - sum)
	sum += plus
	answer += plus * AB[i][0]
	i += 1
print(answer)


(N, M) = map(int, input().split())
D = sorted([list(map(int, input().split())) for n in range(N)])
mon = 0
num = 0
for n in range(N):
	mon += D[n][0] * D[n][1]
	num += D[n][1]
	if M <= num:
		print(mon - D[n][0] * (num - M))
		break


from itertools import accumulate
(N, M) = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])
sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))
num = 0
ans = 0
index_ = -1
for (a, b) in sAB:
	index_ += 1
	num += b
	if num >= M:
		break
	ans += a * b
if index_ == 0:
	ans += sAB[0][0] * M
else:
	ans += sAB[index_][0] * (M - cum_num[index_ - 1])
print(ans)


(N, M) = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
P.sort()
ans = 0
for (a, b) in P:
	m = min(M, b)
	ans += a * m
	M -= m
print(ans)


(N, M) = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort(key=lambda x: x[0])
(x, y) = [list(i) for i in zip(*xy)]
nokori = M
ans = 0
for i in range(N):
	ans += x[i] * min(y[i], nokori)
	nokori -= y[i]
	if nokori <= 0:
		break
print(ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
c = 0
for i in range(n):
	x = min(m, a[i][1])
	c += x * a[i][0]
	m -= x
	if m == 0:
		break
print(c)


(N, M) = map(int, input().split())
d = dict()
shop = set()
ans = 0
for i in range(N):
	(A, B) = map(int, input().split())
	if A in d:
		d[A] += B
	else:
		d[A] = B
	shop.add(A)
shop = list(shop)
shop.sort()
for i in shop:
	if d[i] >= M:
		ans += i * M
		break
	else:
		ans += i * d[i]
		M -= d[i]
print(ans)


(N, M) = map(int, input().split())
AB = sorted((tuple(map(int, input().split())) for _ in range(N)))
ans = 0
for (a, b) in AB:
	k = min(b, M)
	ans += k * a
	M -= k
print(ans)


(N, M) = list(map(int, input().split()))
AB = []
for i in range(N):
	(A, B) = list(map(int, input().split()))
	AB.append([A, B])
AB = sorted(AB, key=lambda x: x[0])
cost = 0
for (a, b) in AB:
	cost += min(max(M, 0), b) * a
	M -= b
	if M <= 0:
		break
print(cost)


li = []
(N, M) = list(map(int, input().split()))
for i in range(N):
	(a, b) = list(map(int, input().split()))
	li.append([a, b])
li.sort()
g = 0
s = 0
for i in range(N):
	if li[i][1] + s < M:
		s += li[i][1]
		g += li[i][1] * li[i][0]
	else:
		g += (M - s) * li[i][0]
		print(g)
		return


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
payment = 0
for i in ab:
	price = i[0]
	amount = i[1]
	if amount > m:
		amount = m
	m -= amount
	payment += amount * price
	if m == 0:
		break
print(payment)


import numpy as np
(n, m) = map(int, input().split())
A = np.array([list(map(int, input().split())) for _ in range(n)], dtype='int64')
ind = np.argsort(A[:, 0])
A = A[ind]
num = 0
money = 0
for (a, b) in A:
	num += b
	if num < m:
		money += a * b
	else:
		money += a * (b - (num - m))
		break
print(money)


from sys import stdin
(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort()
ans = 0
for (i, j) in l:
	a = min(m, int(j))
	ans += a * int(i)
	m -= a
print(ans)


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort()
ans = 0
for i in range(n):
	ans += l[i][0] * min(m, l[i][1])
	m -= l[i][1]
	if m <= 0:
		break
print(ans)


(N, M) = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]
items.sort()
ans = 0
m = 0
for item in items:
	a = min(M - m, item[1])
	m += a
	ans += a * item[0]
print(ans)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
total = 0
for (a, b) in ab:
	num = min(b, m)
	total += a * num
	m -= num
	if m <= 0:
		break
print(total)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[0])
ans = 0
for i in range(n):
	d = min(ab[i][1], m)
	m -= d
	ans += ab[i][0] * d
	if m == 0:
		break
print(ans)


(a, b) = map(int, input().split())
e = []
for i in range(a):
	(c, d) = map(int, input().split())
	e += [[c, d]]
e.sort()
a = i = j = 0
while i < b:
	a += e[j][0] * e[j][1]
	i += e[j][1]
	j += 1
print(a - (i - b) * e[j - 1][0])


(N, M) = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
ans = 0
for i in range(N):
	if M > AB[i][1]:
		M -= AB[i][1]
		ans += AB[i][0] * AB[i][1]
	else:
		ans += AB[i][0] * M
		M = 0
print(ans)


(n, m) = map(int, input().split())
ab = []
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	ab.append([a, b])
ab.sort()
for (a, b) in ab:
	t = min(b, m)
	ans += t * a
	m -= t
print(ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
s = 0
p = 0
for i in range(n):
	if s + a[i][1] >= m:
		p += (m - s) * a[i][0]
		break
	s += a[i][1]
	p += a[i][0] * a[i][1]
print(p)


def resolve():
	(N, M) = map(int, input().split())
	A = []
	for _ in range(N):
		a = list(map(int, input().split()))
		A.append(a)
	ans = 0
	for (i, j) in sorted(A, key=lambda x: x[0]):
		if j >= M:
			ans += M * i
			print(ans)
			return
		ans += i * j
		M -= j
resolve()


import sys
(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A = sorted(A, key=lambda x: x[0])
cost = 0
num = 0
for i in range(N):
	if num + A[i][1] > M:
		print(cost + A[i][0] * (M - num))
		return
	else:
		cost += A[i][0] * A[i][1]
		num += A[i][1]
print(cost)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
l.sort()
c = 0
for (a, b) in l:
	c += min(b, m) * a
	m = max(m - b, 0)
print(c)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab_s = sorted(ab)
res = m
temp = 0
for i in range(n):
	if res <= ab_s[i][1]:
		temp += res * ab_s[i][0]
		print(temp)
		return
	else:
		temp += ab_s[i][1] * ab_s[i][0]
		res -= ab_s[i][1]


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
x = 0
y = 0
for (i, j) in A:
	if M - x < j:
		y += i * (M - x)
		break
	else:
		x += j
		y += i * j
print(y)


(N, M) = map(int, input().split())
AB = []
for _ in range(N):
	AB.append(list(map(int, input().split())))
AB = sorted(AB)
cnt = 0
ans = 0
for ab in AB:
	if cnt + ab[1] <= M:
		cnt += ab[1]
		ans += ab[0] * ab[1]
	else:
		ans += (M - cnt) * ab[0]
		cnt += M - cnt
		break
print(ans)


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


(n, m) = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(n)])
p = 0
for i in range(n):
	(a, b) = l[i]
	if b < m:
		m -= b
		p += a * b
	else:
		p += a * m
		break
print(p)


(n, m) = map(int, input().split())
d = [tuple(map(int, input().split())) for _ in range(n)]
d.sort()
ans = 0
for (ai, bi) in d:
	if m <= bi:
		ans += ai * m
		break
	ans += ai * bi
	m -= bi
print(ans)


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
A = sorted(A, key=lambda x: x[0])
ans = 0
for i in range(n):
	buy = min(m, A[i][1])
	ans += buy * A[i][0]
	m -= buy
print(ans)


(n, m) = map(int, input().split())
ll = []
for i in range(n):
	l = list(map(int, input().split()))
	ll.append(l)
ll.sort()
t = 0
cst = 0
i = 0
while t < m:
	t += ll[i][1]
	cst += ll[i][0] * ll[i][1]
	if t > m:
		cst -= ll[i][0] * (t - m)
	i += 1
print(cst)


(N, M) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)])
res = 0
for (a, b) in AB:
	M -= b
	res += a * b
	if M < 0:
		res += a * M
		break
print(res)


(N, M) = map(int, input().split())
AB = []
for n in range(N):
	AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[0])
m = 0
ans = 0
i = 0
while m < M:
	buy = min(M - m, AB[i][1])
	m += buy
	ans += AB[i][0] * buy
	i += 1
print(ans)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
ans = 0
for AB in AB:
	if M <= AB[1]:
		ans += M * AB[0]
		break
	else:
		ans += AB[0] * AB[1]
		M -= AB[1]
print(ans)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
ans = 0
M_tmp = M
for (i, (Ai, Bi)) in enumerate(AB):
	cnt = min(M_tmp, Bi)
	ans += Ai * cnt
	M_tmp -= cnt
print(ans)


f = lambda : map(int, input().split())
(n, m) = f()
l = []
for _ in range(n):
	l += [tuple(f())]
l.sort()
c = 0
for (a, b) in l:
	if b < m:
		m -= b
		c += a * b
	else:
		c += a * m
		break
print(c)


(N, M) = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])
ans = 0
cnt = 0
last_cnt = 0
for (a, b) in sAB:
	cnt += b
	if cnt < M:
		ans += a * b
		last_cnt = cnt
	else:
		ans += a * (M - last_cnt)
		break
print(ans)


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


def inpl():
	return list(map(int, input().split()))
(N, M) = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: -x[0])
ans = 0
while M:
	(a, b) = X.pop()
	buy = min(M, b)
	ans += a * buy
	M -= buy
print(ans)


(N, M) = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(N)]
li.sort()
n = 0
price = 0
for (i, j) in li:
	n += j
	price += i * j
	if n > M:
		price -= i * (n - M)
		break
print(price)


(N, M) = map(int, input().split())
E = []
for i in range(N):
	E.append(list(map(int, input().split())))
E.sort(key=lambda x: x[0])
ans = 0
i = 0
while M > 0:
	(A, B) = E[i]
	ans += A * min(B, M)
	M = max(M - B, 0)
	i += 1
print(ans)


(N, M) = map(int, input().split())
drinks = []
for i in range(N):
	drinks.append(tuple(map(int, input().split())))
drinks.sort()
cnt = 0
res = 0
for i in range(N):
	res += (min(cnt + drinks[i][1], M) - cnt) * drinks[i][0]
	cnt += drinks[i][1]
	if cnt >= M:
		break
print(res)


(n, m) = map(int, input().split())
shop = [[int(i) for i in input().split()] for _ in range(n)]
shop = list(sorted(shop, key=lambda x: x[0]))
count = 0
money = 0
for x in shop:
	count += x[1]
	money += x[0] * x[1]
	if count >= m:
		excess = count - m
		money -= x[0] * excess
		break
print(money)


(N, M) = [int(x) for x in input().split()]
S = []
for i in range(N):
	(a, b) = [int(x) for x in input().split()]
	S.append((a, b))
S.sort()
a = 0
s = 0
while M > 0:
	a += S[s][0] * min(S[s][1], M)
	M -= S[s][1]
	s += 1
print(a)


(N, M) = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(N)]
S.sort()
ans = 0
for (a, b) in S:
	if M > b:
		M -= b
		ans += a * b
		continue
	ans += a * M
	break
print(ans)


(n, m) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x = sorted(x)
cost = 0
for i in range(n):
	cost += x[i][0] * min(m, x[i][1])
	m -= x[i][1]
	if m < 1:
		break
print(cost)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort()
ans = 0
for (i, j) in AB:
	ans += i * min(M, j)
	M -= min(M, j)
print(ans)


f = lambda : [*map(int, input().split())]
(n, m) = f()
p = sorted((f() for _ in range(n)))
c = 0
for (a, b) in p:
	if m > b:
		c += a * b
		m -= b
	else:
		c += a * m
		break
print(c)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
sm = 0
c = 0
for l in a:
	if l[1] < m - c:
		c += l[1]
		sm += l[1] * l[0]
	else:
		sm += (m - c) * l[0]
		break
print(sm)


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


(n, m) = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(n)]
ab_list.sort()
ans = 0
num = 0
for ab in ab_list:
	ans += ab[0] * ab[1]
	num += ab[1]
	if num >= m:
		i_stop = ab_list.index(ab)
		break
diff_num = num - m
ans -= diff_num * ab_list[i_stop][0]
print(ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0
a = sorted(a, key=lambda x: x[0])
for i in range(n):
	if cnt + a[i][1] < m:
		ans += a[i][0] * a[i][1]
		cnt += a[i][1]
	else:
		ans += a[i][0] * (m - cnt)
		break
print(ans)


(N, M) = [int(i) for i in input().split()]
ab = [[int(j) for j in input().split()] for i in range(N)]
res = 0
ab.sort()
for (a, b) in ab:
	if b < M:
		M -= b
		res += a * b
	else:
		res += a * M
		break
print(res)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for (a, b) in ab:
	buy = min(m, b)
	m -= buy
	ans += a * buy
print(ans)


(n, m) = map(int, input().split())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab.sort()
ans = 0
for i in ab:
	if i[1] >= m:
		ans += m * i[0]
		print(ans)
		exit()
	else:
		ans += i[1] * i[0]
		m -= i[1]


(n, m) = [int(x) for x in input().split()]
a = sorted([[int(x) for x in input().split()] for _ in range(n)], key=lambda x: x[0])
result = 0
for x in a:
	cnt = min(m, x[1])
	result += x[0] * cnt
	m -= cnt
print(result)


import os
import sys

def main():
	(N, M) = list(map(int, input().split()))
	path = []
	for _ in range(N):
		(A, B) = list(map(int, input().split()))
		path.append([A, B])
	path.sort(key=lambda x: x[0])
	ans = [0, 0]
	for p in path:
		if ans[1] + p[1] <= M:
			ans[0] = ans[0] + p[0] * p[1]
			ans[1] += p[1]
		else:
			num = M - ans[1]
			ans[0] = ans[0] + p[0] * num
			ans[1] = ans[1] + num
		if ans[1] == M:
			print(ans[0])
			return

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
x = []
for i in range(n):
	(a, b) = map(int, input().split())
	x.append((a, b))
x.sort()
ans = 0
for (j, k) in x:
	if k < m:
		ans += j * k
		m -= k
	else:
		ans += j * m
		break
print(ans)


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
l.sort(key=lambda x: x[0])
r = m
i = 0
cnt = 0
while r - l[i][1] > 0:
	r -= l[i][1]
	cnt += l[i][0] * l[i][1]
	i += 1
cnt += r * l[i][0]
print(cnt)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[0])
ans = 0
for i in ab:
	m -= i[1]
	ans += i[0] * i[1]
	if m <= 0:
		print(ans + m * i[0])
		break


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sm = 0
cnt = 0
i = 0
while sm != M:
	cnt += A[i][0] * min(A[i][1], M - sm)
	sm += min(A[i][1], M - sm)
	i += 1
print(cnt)


(N, M) = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N)]
AB = sorted(AB)
result = 0
c = M
for (a, b) in AB:
	t = min(c, b)
	c -= t
	result += a * t
print(result)


I = lambda : map(int, input().split())
(n, m) = I()
A = sorted([list(I()) for _ in range(n)])
c = p = 0
for (a, b) in A:
	if c >= m:
		break
	p += a * min(b, m - c)
	c += b
print(p)


(N, M) = map(int, input().split())
ss = []
for _ in range(N):
	(a, b) = map(int, input().split())
	ss.append((a, b))
ss.sort()
m = 0
for (a, b) in ss:
	m += a * min(b, M)
	M -= b
	if M <= 0:
		break
print(m)


(n, m) = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
tot = 0
i = 0
while m > 0:
	c = min(l[i][1], m)
	m -= c
	tot += l[i][0] * c
	i += 1
print(tot)


(N, M) = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
for i in l:
	if M - i[1] > 0:
		M -= i[1]
		ans += i[0] * i[1]
	else:
		ans += i[0] * M
		break
print(ans)


from collections import defaultdict
(N, M) = map(int, input().rstrip().split())
d = defaultdict(lambda : 0)
for _ in range(N):
	(A, B) = map(int, input().rstrip().split())
	d[A] += B
ans = 0
for k in sorted(d.keys()):
	if d[k] <= M:
		ans += k * d[k]
	else:
		ans += k * M
	M -= d[k]
	if M <= 0:
		break
print(ans)


def main():
	(N, M) = list(map(int, input().split()))
	D = [list(map(int, input().split())) for _ in range(N)]
	D.sort()
	ans = 0
	for (a, b) in D:
		if M > b:
			ans += a * b
			M -= b
		else:
			ans += a * M
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, m) = [int(x) for x in input().split()]
ab = [tuple((int(x) for x in input().split())) for _ in range(n)]
ab.sort()
res = 0
for (a, b) in ab:
	if m <= b:
		res += a * m
		break
	res += a * b
	m -= b
print(res)


(N, M) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0])
S = 0
for l in L:
	if l[1] >= M:
		S += l[0] * M
		break
	else:
		S += l[0] * l[1]
		M -= l[1]
print(S)


(N, M) = map(int, input().split())
list1 = []
cost = 0
for i in range(N):
	(A, B) = map(int, input().split())
	list1.append((A, B))
list2 = sorted(list1, key=lambda x: x[0])
for i in range(N):
	if M >= list2[i][1]:
		M -= list2[i][1]
		cost += list2[i][0] * list2[i][1]
	else:
		break
cost += list2[i][0] * M
print(cost)


(n, m) = map(int, input().split())
dic = {}
doll = 0
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
for (k, v) in AB:
	if v < m:
		doll += k * v
		m -= v
	else:
		doll += k * m
		print(doll)
		exit()


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	b = list(map(int, input().split()))
	a.append(b)
a.sort(key=lambda x: x[0])
ans = 0
h = 0
for y in a:
	d = y[0]
	e = y[1]
	if h + e > m:
		ans += (m - h) * d
		h += m - h
	else:
		h += e
		ans += d * e
print(ans)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
	ans += ab[i][0] * ab[i][1]
	cnt += ab[i][1]
	i += 1
print(ans - (cnt - m) * ab[i - 1][0])


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
l.sort()
ans = 0
c = 0
for i in range(n):
	z = l[i][1]
	if c + z <= m:
		ans += l[i][0] * z
		c += z
	else:
		ans += l[i][0] * (m - c)
		break
print(ans)


(n, m) = map(int, input().split())
drink = []
for i in range(n):
	(a, b) = map(int, input().split())
	drink.append([a, b])
drink.sort()
s = 0
for (i, j) in drink:
	if m >= j:
		m -= j
		s += i * j
	else:
		s += m * i
		break
print(s)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
l.sort(key=lambda x: x[0])
ans = 0
count = 0
for i in range(n):
	k = min(m - count, l[i][1])
	count += k
	ans += k * l[i][0]
print(ans)


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N)]
AB.sort()
ans = 0
for (a, b) in AB:
	k = min(b, M)
	ans += a * k
	M -= k
	if M == 0:
		break
print(ans)


(n, m) = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
c = sorted(c)
ans = 0
d = 0
for (a, b) in c:
	if b + d >= m:
		ans += a * (m - d)
		break
	else:
		ans += a * b
		d += b
print(ans)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB_s = sorted(AB)
ans = 0
cnt = 0
for (a, b) in AB_s:
	ans += a * b
	cnt += b
	if cnt >= M:
		ans -= a * (cnt - M)
		print(ans)
		exit()


(n, m) = map(int, input().split())
P = [list(map(int, input().split())) for i in range(n)]
P.sort(key=lambda x: x[0])
ans = 0
for p in P:
	if p[1] < m:
		ans += p[0] * p[1]
		m -= p[1]
	else:
		print(ans + p[0] * m)
		exit()


(N, M) = map(int, input().split())
A_B = [tuple(map(int, input().split())) for _ in range(N)]
A_B = sorted(A_B, key=lambda x: x[1], reverse=True)
A_B = sorted(A_B, key=lambda x: x[0], reverse=False)
pay = 0
drink = M
for (A, B) in A_B:
	if drink <= B:
		pay += A * drink
		break
	else:
		pay += A * B
		drink -= B
print(pay)


(n, m) = map(int, input().split())
l = []
for x in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
l = sorted(l)
r = 0
for x in l:
	r += min(m, x[1]) * x[0]
	m -= x[1]
	if m <= 0:
		break
print(r)


(n, m) = map(int, input().split())
dic = {}
for i in range(n):
	(a, b) = map(int, input().split())
	dic.setdefault(a, 0)
	dic[a] += b
nedan = sorted(dic)
ans = 0
for yen in nedan:
	if dic[yen] < m:
		ans += yen * dic[yen]
		m -= dic[yen]
	else:
		ans += yen * m
		break
print(ans)


(N, M) = map(int, input().split())
l = []
for i in range(N):
	(A, B) = map(int, input().split())
	l.append([A, B])
l.sort(key=lambda x: x[0])
i = 0
ans = 0
while M > l[i][1]:
	M -= l[i][1]
	ans += l[i][0] * l[i][1]
	i += 1
ans += l[i][0] * M
print(ans)


(n, m) = map(int, input().split())
lis = [list(map(int, input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
	while cnt < m:
		if lis[i][1] + cnt < m:
			cnt += lis[i][1]
			mon += lis[i][0] * lis[i][1]
			i += 1
		else:
			break
	print(mon + (m - cnt) * lis[i][0])
else:
	print(m * lis[0][0])


a = list(map(int, input().split()))
b = []
ans = 0
cnt = a[1]
for i in range(a[0]):
	c = list(map(int, input().split()))
	b.append(c)
b = sorted(b)
for i in b:
	if cnt == 0:
		break
	ans += i[0] * min(cnt, i[1])
	cnt -= min(cnt, i[1])
print(ans)


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
num = 0
pay = 0
for (a, b) in A:
	if num + b >= M:
		pay += (M - num) * a
		break
	else:
		pay += a * b
		num += b
print(pay)


(N, M) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]
li = sorted(li, key=lambda x: x[0])
m_sum = 0
for i in li:
	buy = min(M, i[1])
	m_sum += i[0] * buy
	M -= buy
print(m_sum)


(N, M) = map(int, input().split())
AB = []
money = 0
drinks = 0
for i in range(N):
	(A, B) = map(int, input().split())
	AB.append([A, B])
AB.sort()
for i in range(N):
	if 0 < M - drinks < AB[i][1]:
		money += (M - drinks) * AB[i][0]
		break
	elif AB[i][1] <= M - drinks:
		money += AB[i][1] * AB[i][0]
		drinks += AB[i][1]
	else:
		break
print(money)


(N, M) = map(int, input().split())
AB = sorted([tuple(map(int, input().split())) for x in range(N)])
ans = 0
for i in range(N):
	ans += AB[i][0] * max(0, min(AB[i][1], M))
	M -= AB[i][1]
print(ans)


(n, m) = list(map(int, input().split()))
lis = []
ans = 0
for _ in range(n):
	(A, B) = list(map(int, input().split()))
	lis.append((A, B))
lis.sort()
for x in lis:
	(a, b) = x
	if m >= b:
		m -= b
		ans = ans + a * b
	else:
		ans = ans + a * m
		break
print(ans)


(N, M) = map(int, input().split())
inputs = [[int(i) for i in input().split()] for _ in range(N)]
inputs.sort()
count = 0
ans = 0
for (A, B) in inputs:
	if M < 0:
		break
	ans += A * min(B, M)
	M -= B
print(ans)


(n, m) = map(int, input().split())
drink = []
for _ in range(n):
	(a, b) = map(int, input().split())
	drink.append((a, b))
drink.sort(reverse=1)
ans = 0
while m > 0:
	(a, b) = drink.pop(-1)
	ans += a * min(m, b)
	m -= b
print(ans)


(n, m) = map(int, input().split())
ts = sorted((tuple(map(int, input().split())) for _ in range(n)))
res = 0
for (a, b) in ts:
	x = min(b, m)
	res += a * x
	m -= x
print(res)


from operator import itemgetter
(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
i = 0
ans = 0
while m > 0:
	if ab[i][1] <= m:
		m -= ab[i][1]
		ans += ab[i][0] * ab[i][1]
	else:
		ans += ab[i][0] * m
		m = 0
	i += 1
print(ans)


def input2():
	return map(int, input().split())

def input_array():
	return list(map(int, input().split()))
(n, m) = input2()
AB = [input_array() for _ in range(n)]
AB = sorted(AB, key=lambda x: x[0])
ans = 0
for i in range(n):
	a = AB[i][0]
	b = AB[i][1]
	if b > m:
		ans += a * m
		break
	elif b == m:
		ans += a * b
		break
	else:
		ans += a * b
	m -= b
print(ans)


(N, M) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort()
ans = 0
countM = 0
for (a, b) in ab:
	b = min(b, M - countM)
	a *= b
	ans += a
	countM += b
	if countM == M:
		break
print(ans)


(n, m) = map(int, input().split())
d = [tuple(map(int, input().split())) for i in range(n)]
d.sort()
x = 0
for i in range(len(d)):
	x += d[i][0] * min(d[i][1], m)
	m -= min(d[i][1], m)
	if m == 0:
		break
print(x)


(n, m) = [int(v) for v in input().split()]
drink_list = sorted([[int(v) for v in input().split()] for i in range(n)])
total = 0
for i in drink_list:
	buy = min(m, i[1])
	total += i[0] * buy
	m -= buy
print(total)


(a, b) = map(int, input().split())
c = [list(map(int, input().split())) for i in range(a)]
c = sorted(c, key=lambda x: x[0])
ans = 0
for i in range(a):
	if b == 0:
		break
	elif b >= c[i][1]:
		b -= c[i][1]
		ans += c[i][1] * c[i][0]
	else:
		ans += b * c[i][0]
		break
print(ans)


(n, m) = map(int, input().split())
st = []
for _ in range(n):
	st.append(tuple(map(int, input().split())))
st.sort()
i = 0
c = 0
while m > 0:
	b = min(m, st[i][1])
	c += b * st[i][0]
	m -= b
	i += 1
print(c)


(N, M) = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for _ in range(N)]
ab.sort(key=lambda x: x[0])
ans = 0
for (a, b) in ab:
	m = M
	M = max(M - b, 0)
	ans += a * (m - M)
print(ans)


(N, M) = map(int, input().split())
L = sorted([tuple(map(int, input().split())) for i in range(N)])
ans = 0
for (a, b) in L:
	if M > b:
		ans += a * b
		M -= b
	else:
		ans += a * M
		break
print(ans)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
money = 0
for (a, b) in AB:
	if M > b:
		money += a * b
		M -= b
	else:
		money += a * M
		break
print(money)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
ans = 0
d = 0
for i in range(n):
	s = min(m - d, ab[i][1])
	ans += ab[i][0] * s
	d += s
	if d == m:
		break
print(ans)


(N, M) = map(int, input().split())
sum = 0
A = [[int(i) for i in input().split()] for j in range(N)]
A.sort()
i = 0
while True:
	if A[i][1] >= M:
		sum += A[i][0] * M
		break
	else:
		sum += A[i][0] * A[i][1]
	M -= A[i][1]
	i += 1
print(sum)


(n, m) = map(int, input().split())
s = [[i for i in map(int, input().split())] for _ in range(n)]
c = 0
for (a, b) in sorted(s):
	c += min(m, b) * a
	m -= b
	if m < 1:
		break
print(c)


(n, m) = map(int, input().split())
drk = [list(map(int, input().split())) for _ in range(n)]
drk.sort()
i = 0
ans = 0
while m > 0:
	(a, b) = drk[i]
	if m >= b:
		ans += a * b
		m = m - b
	else:
		ans += a * m
		m = 0
	i += 1
print(ans)


(N, M) = map(int, input().split())
AB = sorted((list(map(int, input().split())) for i in range(N)))
ans = 0
for (A, B) in AB:
	if B >= M:
		print(ans + A * M)
		exit()
	else:
		ans += A * B
		M -= B


(N, M) = list(map(int, input().split()))
price = [[] for i in range(N)]
for i in range(N):
	(a, b) = list(map(int, input().split()))
	price[i] = [a, b]
price.sort()
m = 0
money = 0
for i in range(N):
	if m + price[i][1] < M:
		money += price[i][0] * price[i][1]
		m += price[i][1]
	else:
		money += price[i][0] * (M - m)
		break
print(money)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
ll = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (p, c) in ll:
	ans += p * min(m, c)
	m -= c
	if m < 1:
		break
print(ans)


(N, M) = map(int, input().split())
ab = []
for _ in range(N):
	ab.append(list(map(int, input().split())))
ab.sort()
y = d = 0
for i in ab:
	y += i[0] * i[1]
	d += i[1]
	if d >= M:
		print(y - (d - M) * i[0])
		exit()


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
money = 0
for (a, b) in AB:
	if b >= M:
		money += a * M
		break
	money += a * b
	M -= b
print(money)


(N, M) = map(int, input().split())
drinks = list()
for i in range(N):
	(a, b) = map(int, input().split())
	drinks.append((a, b))
drinks.sort(key=lambda x: x[0])
ans = 0
while M > 0:
	(a, b) = drinks.pop(0)
	if M <= b:
		ans += a * M
		M = 0
	else:
		ans += a * b
		M -= b
print(ans)


from collections import deque
(n, m) = map(int, input().split())
l = deque(sorted([list(map(int, input().split())) for i in range(n)]))
money = 0
while m != 0:
	(a, b) = l.popleft()
	t = min(b, m)
	m -= t
	money += a * t
print(money)


(n, m) = map(int, input().split())
alist = [list(map(int, input().split())) for l in range(n)]
alist.sort(key=lambda x: x[0])
ans = 0
cnt = m
for i in range(n):
	if alist[i][1] < cnt:
		ans += alist[i][0] * alist[i][1]
		cnt -= alist[i][1]
	else:
		ans += cnt * alist[i][0]
		break
print(ans)


(n, m) = map(int, input().split())
drinks = sorted([list(map(int, input().split())) for _ in range(n)])
(rest, res) = (m, 0)
for i in range(n):
	buy = min(rest, drinks[i][1])
	res += buy * drinks[i][0]
	rest -= buy
print(res)


(N, M) = map(int, input().split())
L = []
for _ in range(N):
	L.append(list(map(int, input().split())))
L.sort()
ans = 0
for l in L:
	if M > 0:
		ans += l[0] * min(M, l[1])
		M -= l[1]
	else:
		break
print(ans)


(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
ans = 0
for x in li:
	ans += x[0] * min(m, x[1])
	m -= min(m, x[1])
print(ans)


(n, m) = map(int, input().split())
AB = [[int(i) for i in input().split()] for j in range(n)]
AB.sort()
res = 0
for (a, b) in AB:
	m -= b
	if m >= 0:
		res += a * b
	else:
		m += b
		res += a * m
		break
print(res)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[0])
ans = 0
d = 0
i = 0
while d < m:
	ans += ab[i][0] * min(m - d, ab[i][1])
	d += ab[i][1]
	i += 1
print(ans)


(n, m) = map(int, input().split())
ans = 0
shop = [tuple(map(int, input().split())) for _ in range(n)]
shop.sort()
for (price, num) in shop:
	num = min(m, num)
	ans += price * num
	m -= num
print(ans)


(N, M) = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(N)]
data.sort()
price = 0
for d in data:
	price += d[0] * min(M, d[1])
	M -= d[1]
	if M <= 0:
		break
print(price)


(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]
li.sort()
cnt = ans = 0
for (i, j) in li:
	cnt += j
	if cnt >= m:
		print(ans + i * (m + j - cnt))
		break
	ans += i * j


(n, m) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
L = sorted(L, key=lambda x: x[0])
limit = m
ans = 0
for i in range(n):
	if limit <= 0:
		break
	ans += min(limit, L[i][1]) * L[i][0]
	limit -= L[i][1]
print(ans)


(n, m) = map(int, input().split())
ab = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	ab.append((a, b))
ab.sort()
num = 0
money = 0
for h in range(n):
	num += ab[h][1]
	if num < m:
		money += ab[h][0] * ab[h][1]
	elif num == m:
		money += ab[h][0] * ab[h][1]
		break
	else:
		money += ab[h][0] * ab[h][1] - (num - m) * ab[h][0]
		break
print(money)