CodeEff/ECCO huggingface dataset:
# Original solution
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
price_list = []

for _ in range(N):
    tmp = read_int()
    if tmp[0] not in price_list:
        price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list.sort()

def solve():
    price = 0
    global M
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

# Optimized solution
# from collections import defaultdict
# N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
# price_list = []

price_set = set()
for _ in range(N):
    tmp = read_int()
    # if tmp[0] not in price_set:
        # price_list.append(tmp[0])
    price_set.add(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
# price_list.sort(reverse=True)
price_list = sorted(list(price_set))

# price_howmany = dict(price_howmany)

def solve():
    price = 0
    global M
    # while M > 0:
        # low_price = min(price_howmany.keys())
        # low_price = price_list.pop()
        # many = min(M,price_howmany.pop(low_price))
        # price += many * low_price
        # M -= many
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()
# Original solution
N,M=list(map(int,input().split()))
S=[]
for i in range(N):
    A,B=list(map(int,input().split()))
    S.append([A,B])

S.sort()
m=0

for i in range(M):
    for j in range(N):
        if S[j][1]!=0:
            m+=S[j][0]
            S[j][1]-=1
            break

print(m)



    

# Optimized solution
N,M=list(map(int,input().split()))
S=[]
for i in range(N):
    A,B=list(map(int,input().split()))
    S.append([A,B])

S.sort()
m=0
while M>0:
    for i in range(N):
        if S[i][1]<=M:
            m+=S[i][0]*S[i][1]
            M-=S[i][1]
        else:
            m+=S[i][0]*M
            M=0
            break

print(m)
# Original solution
N, M = [int(x) for x in input().split()]

class value():
  def __init__(self, a, b):
    self.a = a
    self.b = b
  def __gt__(self, other):
    return self.a > other.a
  def __ge__(self, other):
    return self.a >= other.a

V = []
for i in range(N):
  a, b = [int(x) for x in input().split()]
  V.append(value(a, b))
  V.sort()

money = 0
i = 0

while True:
  v = V[i]
  if M <= v.b:
    break
  else:
    money += v.a * v.b
    M -= v.b
    i += 1
money += v.a * M
print(money)

# Optimized solution
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - count) * a
    break
print(money)
# Original solution
import heapq

n,m = list(map(int,input().split(" ")))
li = []
heapq.heapify(li)

for i in range(n):
    a,b = list(map(int,input().split(" ")))
    for j in range(b):
        heapq.heappush(li,a)

result = 0
for i in range(m):
    result += heapq.heappop(li)
print(result)

# Optimized solution


n,m = list(map(int,input().split(" ")))
li = []

for i in range(n):
    a,b = list(map(int,input().split(" ")))
    li.append((a,b))

li.sort()

result = 0
count = 0
flag = False
for i in range(m):
    for j in range(li[i][1]):
        result += li[i][0]
        count += 1
        if count == m:
            flag = True
            break
    if flag:
        break
print(result)
# Original solution
N, M = list(map(int, input().split()))
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB.sort(key=lambda x:x[0])

kane = 0
hon = 0
for i in range(N):
    if hon + AB[i][1] < M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        continue
    elif hon + AB[i][1] == M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        print(kane)
        break
    else:
        for j in range(AB[i][1]):
            hon += 1
            kane += AB[i][0]
            if hon == M:
                print(kane)
                break

# Optimized solution
N, M = list(map(int, input().split()))
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB.sort(key=lambda x:x[0])

kane = 0
hon = 0
for i in range(N):
    if hon + AB[i][1] < M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        continue
    elif hon + AB[i][1] == M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        print(kane)
        break
    else:
        kane += (M - hon) * AB[i][0]
        print(kane)
        break
# Original solution
N, M = list(map(int, input().split()))
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB.sort(key=lambda x:x[0])

kane = 0
hon = 0
for i in range(N):
    if hon + AB[i][1] < M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        continue
    elif hon + AB[i][1] == M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        print(kane)
        break
    else:
        kane += (M - hon) * AB[i][0]
        print(kane)
        break

# Optimized solution
N, M = list(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 a, b in AB:
    if b <= M:
       ans += a * b
       M -= b
    else:
        ans += a * M
        break
    if M == 0:
        break
print(ans)
# Original solution
a, b = list(map(int, input().split()))
c = [list(map(int, input().split())) for i in range(a)]
c.sort()
d = 0
e = 0
for i in range(a):
    if c[i][1] + d < b:
        e += c[i][1] * c[i][0]
        d += c[i][1]
    else:
        e += (b - d) * c[i][0]
        d += b - d
print(e)


# Optimized solution
a, b = list(map(int, input().split()))
c = []
for i in range(a):
    d, e = list(map(int, input().split()))
    c.append([d, e])
c.sort()
g = 0
for i in range(a):
    f = min(b, c[i][1])
    b -= f
    g += f * c[i][0]
    if b == 0:
        break
print(g)
# Original solution
N, M = list(map(int, input().split()))
shops = [None] * N
for i in range(N):
  shops[i] = list(map(int, input().split()))
shops.sort()
cnt = 0
ans = 0
while cnt < M:
  shop = shops.pop(0)
  if cnt + shop[1] >= M:
    ans += (M - cnt) * shop[0]
    cnt = M
  else:
    ans += shop[0] * shop[1]
    cnt += shop[1]
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
shops = [None] * N
for i in range(N):
  shops[i] = list(map(int, input().split()))
shops.sort()
cnt = 0
ans = 0
for i in range(N):
  shop = shops[i]
  ans += shop[0] * shop[1]
  cnt += shop[1]
  if cnt > M:
    ans -= (cnt - M) * shop[0]
    break
print(ans)
# Original solution
def key_func(n):
    return n[0]

n,m = list(map(int, input().split(" ")))
a_b = []
for i in range(n):
    a_b.append(list(map(int,input().split(" "))))

money = 0

while m > 0:
    ind = a_b.index(min(a_b,key=key_func))
    i = min(m,a_b[ind][1])
    money = money + a_b[ind][0]*i
    m = m - i
    del a_b[ind]

print(money)

# Optimized solution
def key_func(n):
    return n[0]

n,m = list(map(int, input().split(" ")))
a_b = []
for i in range(n):
    a_b.append(list(map(int,input().split(" "))))

a_b.sort(key=key_func)

money = 0

for item in a_b:
    i = min(m,item[1])
    money = money + item[0]*i
    m = m - i
    if m <= 0:
        break

print(money)
# Original solution
n, m = list(map(int, input().split()))
ll = []

for i in range(n):
    l = list(map(int, input().split()))
    ll.append(l)

i = 0
while i < n-1:
    k = i+1
    while k <= n-1:
        if ll[i][0] > ll[k][0]:
            ll[i], ll[k] = ll[k], ll[i]
        k += 1
    i+=1
s = 0
cst = 0
while m > 0:
    cst += ll[s][0] * ll[s][1]
    m -= ll[s][1]
    s += 1
print((cst + m*ll[s-1][0]))

# Optimized solution
n, m = list(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)
# Original solution
N,M = (int(x) for x in input().split())
A=[]
B=[]
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append(a)
    B.append(b)
ans = 0

while M > 0:
    ind = A.index(min(A))
    b = B.pop(ind)

    if M < b:
        b = M
        M = 0
    else:
        M -= b

    ans += A.pop(ind) * b
    
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
drink = []
for _ in range(N):
    drink.append(list(map(int, input().split())))
drink.sort()
ans = 0
while M > 0:
    AB = drink.pop(0)
    b = min(M, AB[1])
    ans += b * AB[0]
    M -= b
print(ans)
# Original solution
N, M = list(map(int, input().split()))
drink = []
for _ in range(N):
    drink.append(list(map(int, input().split())))
drink.sort()
ans = 0
while M > 0:
    AB = drink.pop(0)
    b = min(M, AB[1])
    ans += b * AB[0]
    M -= b
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
drink, sumA, sumB = [], 0, 0
for _ in range(N):
    A,B = list(map(int, input().split()))
    drink.append([A, B])
    sumA += A*B
    sumB += B 

if M == sumB:
    print(sumA)
elif M > sumB // 2:
    drink.sort(reverse=True)
    ans, exM = sumA, sumB - M
    while exM > 0:
        AB = drink.pop(0)
        b = min(exM, AB[1])
        ans -= b * AB[0]
        exM -= b
    print(ans)
else:
    drink.sort()
    ans = 0
    while M > 0:
        AB = drink.pop(0)
        b = min(M, AB[1])
        ans += b * AB[0]
        M -= b
    print(ans)
# Original solution
N, M= list(map(int, input().split()))
A = []
B = []
for i in range(N):
    a,b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
count = 0
cost = 0
while count < M:
    pos = A.index(min(A))
    cost += A[pos] * min(B[pos],M-count)
    count += min(B[pos],M-count)
    A.pop(pos)
    B.pop(pos)
        
print(cost)

# Optimized solution
N, M= list(map(int, input().split()))
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
count = 0
cost = 0
i = 0
while count < M:
    cost += A[i][0] * min(A[i][1],M-count)
    count += min(A[i][1],M-count)
    i += 1    
print(cost)
# Original solution
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(N)]

nl = []
for i in range(N):
    for j in range(l[i][1]):
        nl.append(l[i][0])
    
sorted_nl = sorted(nl)

ans = 0
for i in range(M):
    ans += sorted_nl[i]
    
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(N)]

sl = sorted(l)
buy = 0
ans = 0
for i in range(N):
    for j in range(sl[i][1]):
        if buy < M:
            ans += sl[i][0]
            buy += 1
        else:
            break

print(ans)
# Original solution
N, M = [int(c) for c in input().split()]

shops = []
for _ in range(N):
    ab = [int(c) for c in input().split()]
    shops.append(ab)

cost = 0
bought = 0
for i in range(N):
    if i < N - 1:
        target = shops[i][0]
        min_i = i
        for j in range(i+1, N):
            if shops[j][0] < shops[min_i][0]:
                min_i = j
        shops[min_i], shops[i] = shops[i], shops[min_i]

    k = 0
    while k < shops[i][1]:
        if bought == M:
            break
        cost += shops[i][0]
        k += 1
        bought += 1

    if bought == M:
        break

print(cost)

# Optimized solution
N, M = [int(c) for c in input().split()]

shops = []
for _ in range(N):
    ab = [int(c) for c in input().split()]
    shops.append(ab)

cost = 0
bought = 0
s_shops = sorted(shops)

for shop in s_shops:
    buying = 0
    while buying < shop[1]:
        if bought == M:
            break
        cost += shop[0]
        buying += 1
        bought += 1

    if bought == M:
        break

print(cost)
# Original solution
N, M = list(map(int, input().split()))
e = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    e.append([a, b])

e = list(sorted(e, key=lambda x: x[0]))
# 安値から

cost = 0
cnt = M
e_i = 0
while cnt > 0:
    can_buy = min(cnt, e[e_i][1])
    # 必要本数か売っている本数のうち少ない方

    cost += can_buy * e[e_i][0]
    e[e_i][1] -= can_buy
    cnt -= can_buy
    if e[e_i][1] == 0:
        e_i += 1

print(cost)


# Optimized solution
n, m = list(map(int, input().split()))
e = [tuple(map(int, input().split())) for _ in range(n)]
e.sort()  # 金額昇順
ans = 0
rest = m
for a, b in e:
    use = min(rest, b)
    ans += use * a
    rest -= use
    if rest == 0:
        break
print(ans)
# Original solution
from functools import reduce
N, M = list(map(int, input().split()))
A, B = list(zip(*sorted((list(map(int, input().split())) for _ in range(N)))))
ans = reduce(lambda acc, t: (acc[0] + t[0] * min(max(0, M - acc[1]), t[1]), acc[1] + t[1]), list(zip(A, B)), (0, 0))[0]
print(ans)


# Optimized solution
from functools import reduce
# 入力
N, M = list(map(int, input().split()))
A, B = list(zip(*(list(map(int, input().split())) for _ in range(N))))

# 1本あたりの値段が安い店から順に購入
ans = reduce(
    lambda acc, t: (
        acc[0] + t[0] * min(t[1], M - acc[1]),
        acc[1] + t[1]
    ) if acc[1] < M else
    acc,
    sorted(zip(A, B)),
    (0, 0)
)[0]

# 出力
print(ans)
# Original solution
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
cnt = 0
yen = 0

sortkey = lambda val: val[0]
AB.sort(key=sortkey)

for i in range(N):
    for j in range(int(AB[i][1])):
        cnt += 1
        yen += AB[i][0]
        if cnt == M:
            print(yen)
            break


# Optimized solution
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
cnt = 0
yen = 0

sortkey = lambda val: val[0]
AB.sort(key=sortkey)

for i in range(N):
    if M >= AB[i][1]:
        cnt += AB[i][1]
        yen += AB[i][0] * AB[i][1]
        M -= AB[i][1]
    elif M < AB[i][1]:
        cnt += M
        yen += AB[i][0] * M
        M = 0
    if M == 0:
        print(yen)
        break
# Original solution
from operator import itemgetter

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
#print(ab)
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)

# Optimized solution
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.sort()
ans=0
t=m
for i in range(n):
  if ab[i][1]<t:
    ans+=ab[i][0]*ab[i][1]
    t-=ab[i][1]
  else:
    ans+=ab[i][0]*t
    print(ans)
    exit()
# Original solution
N,M = list(map(int, input().split(" ")))
A=["" for i in range(N)]
B=["" for i in range(N)]
for i in range(N):
    A[i],B[i] = list(map(int, input().split(" ")))
total_num=0
total_mon=0
while True:
    min_a = min(A)
    ind = A.index(min_a)
    add = B[ind]
    total_num+=add
    if total_num>=M:
        add = add - (total_num-M)
        total_mon+=add*min_a
        break
    total_mon+=add*min_a
    A.pop(ind)
    B.pop(ind)
print(total_mon)


# Optimized solution
N,M = list(map(int, input().split(" ")))
AB=["" for i in range(N)]
for i in range(N):
    A,B = list(map(int, input().split(" ")))
    AB[i] = [A,B]
total_num=0
total_mon=0
AB = sorted(AB)
for i,t in enumerate(AB):
    add = t[1]
    total_num+=add
    if total_num>=M:
        add = add - (total_num-M)
        total_mon+=add*t[0]
        break
    total_mon+=add*t[0]
print(total_mon)
# Original solution
n,m = list(map(int,input().split()))
cost = []
for i in range(n):
    a,b = list(map(int,input().split()))
    cost.append([a,b])
cost.sort()
cnt = 0
price = 0
for i in range(n):
    if cnt + cost[i][1] <= m:
        price += cost[i][0] * cost[i][1]
        cnt += cost[i][1]
    else:
        price += (m-cnt)*cost[i][0]
        print(price)
        exit()
print(price)


# Optimized solution
n,m = list(map(int,input().split()))
drink = []
for i in range(n):
    a,b = list(map(int,input().split()))
    drink.append((a,b))
drink.sort()
ans = 0
for i in range(n):
    if m == 0:
        break
    if m >= drink[i][1]:
        ans += drink[i][0] * drink[i][1]
        m -= drink[i][1]
    else:
        ans += m*drink[i][0]
        m = 0
print(ans)
# Original solution
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])
answer = 0
for ab in AB:
    if M - ab[1] <= 0:
        answer += M * ab[0]
        break
    else:
        answer += ab[0] * ab[1]
        M -= ab[1]
print(answer)


# Optimized solution
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
AB = [lr() for _ in range(N)]
AB.sort()
drink = 0
answer = 0
for i in range(N):
    cost = AB[i][0]
    limit = AB[i][1]
    if drink + limit < M:
        answer += cost * limit
        drink += limit
    else:
        x = M - drink
        answer += cost * x
        break

print(answer)
# Original solution
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
AB = [lr() for _ in range(N)]
AB.sort()
drink = 0
answer = 0
for i in range(N):
    cost = AB[i][0]
    limit = AB[i][1]
    if drink + limit < M:
        answer += cost * limit
        drink += limit
    else:
        x = M - drink
        answer += cost * x
        break

print(answer)


# Optimized solution
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
AB = [lr() for _ in range(N)]
AB.sort()
answer = 0
for cost, num in AB:
    if M - num > 0:
        answer += cost * num
        M -= num
    else:
        answer += cost * M
        break

print(answer)
# Original solution
import sys
N, M = list(map(int, input().split()))

lis_A = []
lis_B = []

for _ in range(N):
    A, B = list(map(int, input().split()))
    lis_A.append(A)
    lis_B.append(B)

cost  = 0
count  = 0

while True:
    if N == 1:
        print((lis_A[0] * lis_B[0]))
        sys.exit()
    saiyasu = lis_A.index(min(lis_A))



    #ものを買う時に、Mをオーバーするなら処理
    if (lis_B[saiyasu] + count) <= M:
        cost = ((lis_B[saiyasu] * lis_A[saiyasu]) + cost)
        count  = lis_B[saiyasu] + count
        lis_A.pop(saiyasu)
        lis_B.pop(saiyasu)
    else:
        cost = (((M - count) * lis_A[saiyasu]) + cost)
        break
print(cost)


# Optimized solution
import sys
N, M = list(map(int, input().split()))

lis_A = []
lis_B = []

for _ in range(N):
    A, B = list(map(int, input().split()))
    lis_A.append(A)
    lis_B.append(B)

c = list(zip(lis_A, lis_B))
sorted_c = sorted(c)
lis_A, lis_B = list(zip(*sorted_c))


cost  = 0
count  = 0

while True:
    if N == 1:
        print((lis_A[0] * lis_B[0]))
        sys.exit()


    for i in range(len(lis_A)):
        if (lis_B[i] + count) <= M:
            cost = (lis_A[i]*lis_B[i]) + cost
            count = lis_B[i] + count
        else:
            cost = (((M - count) * lis_A[i]) + cost)
            print(cost)
            sys.exit()
# Original solution
def main():
	N, M = list(map(int, input().split()))
	A = []
	B = []
	for i in range(N):
		a, b = list(map(int, input().split()))
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		minp = min(A)
		for i in range(N):
			if A[i] == minp:
				mc = B[i]
				A[i] = 10**10
				break
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += minp
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += minp * mc
	return

if __name__ == '__main__':
	main()


# Optimized solution
def main():
	N, M = list(map(int, input().split()))
	S = []
	for i in range(N):
		a, b = list(map(int, input().split()))
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()
# Original solution
def main():
	N, M = list(map(int, input().split()))
	S = []
	for i in range(N):
		a, b = list(map(int, input().split()))
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()


# Optimized solution
N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]

AB = sorted(AB, key = lambda ab:ab[0])

cost = 0
count = 0
for a, b in AB:
	if b < M - count:
		cost += a * b
		count += b
	else:
		t = M - count
		cost += a * t
		count += t
		break
print(cost)
# Original solution
import sys
N,M = list(map(int,input().split()))
shops = dict()
price = []
takahashi = 0
money = 0
for i in range(N):
    bottle,stock = list(map(int,input().split()))
    if bottle not in shops:
        shops[bottle] = 0
    shops[bottle] += stock
    if bottle not in price:
        price.append(bottle)
price.sort()
for y in price:
    if shops[y] <= (M-takahashi):
        takahashi += shops[y]
        money += shops[y]*y
        shops[y] = 0
        if takahashi == M:
            print(money)
            sys.exit(0)
    else:
        money += y*(M-takahashi)
        takahashi += (M-takahashi)
        shops[y] -= (M-takahashi)
        if takahashi == M:
            print(money)
            sys.exit(0)

# Optimized solution
N,M = list(map(int,input().split()))
shops = []
for i in range(N):
    price,B = list(map(int,input().split()))
    shops.append([price,B])
shops.sort()
i = 0
money = 0
while M > 0:
    if shops[i][1] > M:
        money += M*shops[i][0]
        break
    else:
        money += shops[i][1] * shops[i][0]
        M -= shops[i][1]
    i += 1
print(money)
# Original solution
n_store, n_drink = [int(i) for i in input().split()]
stores = [[int(i) for i in input().split()] for _ in range(n_store)]  # price, n_stock
stores.sort(key=lambda x: x[0], reverse=True)  # priceでソート

ans = 0
while True:
    if n_drink == 0:
        # n_drinkが0になったら終了
        break
    store = stores.pop()
    price, n_stock = store

    n_buy = min(n_stock, n_drink)  # stockがなくなるかn_drinkに到達するまで買う
    ans += n_buy * price
    n_drink -= n_buy
print(ans)


# Optimized solution
n_store, n_drink = [int(i) for i in input().split()]
stores = [[int(i) for i in input().split()] for _ in range(n_store)]  # price, n_stock
stores.sort(key=lambda x: x[0], reverse=True)  # priceでソート

ans = 0
while n_drink:
    store = stores.pop()
    price, n_stock = store

    n_buy = min(n_stock, n_drink)  # stockがなくなるかn_drinkに到達するまで買う
    ans += n_buy * price
    n_drink -= n_buy
print(ans)
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

N, M = list(map(int, input().split()))
drinks = list()

for i in range(N):
    a, b = list(map(int,input().split()))
    for j in range(b):
        drinks.append(a)

drinks.sort()

ans = sum(drinks[:M])

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

N, M = list(map(int, input().split()))
drinks = list()

for i in range(N):
    a, b = list(map(int,input().split()))
    drinks.append((a,b))

drinks.sort(key = lambda x: x[0])
#print(drinks)
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,M)
print(ans)