CodeEff/ECCO huggingface dataset:
# Original solution
n, m = list(map(int, input().split()))

A = []
B = []
cnt = 0
ans = 0

for _ in range(n):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)


while cnt < m:
    A_min = min(A)
    A_min_index = A.index(A_min)
    if cnt + B[A_min_index] < m:
        ans += A_min * B[A_min_index]
        cnt += B[A_min_index]
        A.pop(A_min_index)
        B.pop(A_min_index)
    else:
        for i in range(B[A_min_index]):
            if cnt == m:
                break
            ans += A_min
            cnt += 1

print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
drink = sorted([list(map(int, input().split())) for _ in range(n)])

ans = 0

for a,b in drink:
    ans += a*min(b,m)
    m -= min(b,m)
    if m == 0:
        break

print(ans)
# Original solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = list(map(int, input().split()))
    all = []
    for i in range(n):
        all.append(list(map(int, input().split())))
    all.sort()
    for i in range(n):
        if m >= all[i][1]:
            m -= all[i][1]
            ans += all[i][0]*all[i][1]
        else:
            ans += all[i][0]*(m)
            break
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = list(map(int, input().split()))
    all = []
    for i in range(n):
        all.append(list(map(int, input().split())))
    all.sort()
    for a,b in all:
        if m >= b:
            m -= b
            ans += a*b
        else:
            ans += a*(m)
            break
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
N, M = list(map(int, input().split()))
A = []
B = []

a, b = list(map(int, input().split()))

A.append(a)
B.append(b)

if N != 1:
    for n in range(N-1):
        a, b = list(map(int, input().split()))
        swi = 0
        for j in range(len(A)):
            if A[j] > a:
                A.insert(j, a)
                B.insert(j, b)
                swi = 1
                break
        if swi == 0:
            A.append(a)
            B.append(b)

cntSum = 0
moneySum = 0

for n in range(N):
    if cntSum + B[n] > M:
        moneySum += A[n] * (M - cntSum)
        cntSum += M - cntSum
        break
    else:
        cntSum += B[n]
        moneySum += A[n] * B[n]

print(moneySum)


# Optimized solution
n, m = list(map(int, input().split()))
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for i in range(n):
    ab = abList[i]
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)
# Original solution
n, m = list(map(int, input().split()))
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for i in range(n):
    ab = abList[i]
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)


# Optimized solution
n, m = list(map(int, input().split()))
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)
# Original solution
n, m = list(map(int, input().split()))
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)


# Optimized solution
n, m = list(map(int, input().split()))
abList = [list(map(int, input().split())) for _ in range(n)]
abList.sort()
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)
# Original solution
N,M=list(map(int,input().split()))
sum=0
A=[int(i) for i in range(N)]
B=[int(i) for i in range(N)]
for i in range(N):
  A[i],B[i]=list(map(int,input().split()))
while True:
  K=B[A.index(min(A))]
  if K>=M:
    print((sum+min(A)*M))
    break
  else:
    sum+=K*min(A)
  M-=K
  A[A.index(min(A))]=max(A)+1

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

ab.sort()
ans = 0
while m != 0:
    tab = ab.pop(0)
    ans += min(tab[1], m)* tab[0]
    m = max(0, m - tab[1])
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]

ab.sort()
ans = 0
for tab in ab:
    if m < 0:
        break
    ans += min(tab[1], m)* tab[0]
    m -= tab[1]
print(ans)
# Original solution
n, m = list(map(int, input().split()))
ab = []
for _ in range(n):
    ab.append(list(map(int,input().split())))

#%%

# print(n, m, ab)
# n, m, ab = 4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]]


#%%
ab.sort()

#%%
ans = 0
num = 0
while num < m:
    a0 = ab[0][0]
    b0 = ab[0][1]
    if b0 >= m - num:
        ans += a0 * (m - num)
        break
    else:
        ans += a0 * b0
        num += b0
        ab.remove([a0, b0])
#%%
print(ans)
#%%


# Optimized solution
n, m = list(map(int, input().split()))
ab = []
prod = [0]
prod_cum = [0]

num_cum = [0]
for i in range(n):
    a, b = list(map(int, input().split()))
    ab.append([a,b])


#%%
ab.sort()

for i in range(n):
    a, b = ab[i][0],ab[i][1]
    # prod.append(a*b)
    prod_cum.append(a*b + prod_cum[-1])
    num_cum.append(b + num_cum[-1])
ab = [[0,0]] + ab
# print(ab)
# print(prod)
# print(prod_cum)
# print(num_cum)
# print(n, m, ab)
# n, m, ab = 4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]]


#%%
ans = 0
prod = 0
for i in range(0, n+1):
    if num_cum[i] >= m:
        print((prod_cum[i] - ab[i][0] * (num_cum[i]-m)))
        break



#%%
# ans = 0
# num = 0
# while num < m:
#     a0 = ab[0][0]
#     b0 = ab[0][1]
#     if b0 >= m - num:
#         ans += a0 * (m - num)
#         break
#     else:
#         ans += a0 * b0
#         num += b0
#         ab.remove([a0, b0])
#%%
# print(ans)
#%%
# Original solution
#Energy Drink Collector
N, M = list(map(int, input().strip().split()))
A = []
B = []
for n in range(N):
	a, b = list(map(int, input().strip().split()))
	A.append(a)
	B.append(b)
total   = 0
collect = 0
while True:
	min_i = A.index(min(A))
	if collect + B[min_i] < M:
		total += A[min_i]*B[min_i]
		collect += B[min_i]
		del A[min_i]
		del B[min_i]
	else:
		total += A[min_i]*(M - collect)
		collect = M
		break
print(total)	

# Optimized solution
#Energy Drink Collector
N, M = list(map(int, input().strip().split()))

list = [list(map(int, input().strip().split())) for i in range(N)]	
list.sort(key = lambda x : x[0])
sum = 0
cnt = 0
for a, b in list:
	if cnt + b < M:
		sum += a*b
		cnt += b
	else:
		sum += a*(M - cnt)
		break

print(sum)
# Original solution
N_M = [int(x.strip()) for x in input().split()]
price_maxnum_list = [[int(i) for i in input().split()] for i in range(0, N_M [0])]
price_list = [i[0] for i in price_maxnum_list]
maxnum_list = [i[1] for i in price_maxnum_list]
if len(set(price_list)) ==1:
    print((price_list[0]*N_M[1]))
else:
    total = 0
    nokori = N_M[1]
    while nokori > 0:
        ind = price_list.index(min(price_list))
        total += min(price_list) * min(maxnum_list[ind], nokori)
        nokori -= min(maxnum_list[ind], nokori)
        price_list.pop(ind)
        maxnum_list.pop(ind)
    print(total)

# Optimized solution
N_M = [int(x.strip()) for x in input().split()]
price_l = [[int(i) for i in input().split()] for i in range(0, N_M[0])]
price_l.sort(key=lambda x: x[0])
total = 0
remain = N_M[1]
while remain > 0:
    if len(price_l)<1:
        break
    price_n = price_l.pop(0)
    total += price_n[0] * min(price_n[1], remain)
    remain -= min(price_n[1], remain)
print(total)
# Original solution

N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

A.sort(key=lambda x: x[0])

total = 0
remain = M
for x in A:
    yen, num = x
    purchase = min(num, remain)
    total += (yen * purchase)
    remain -= purchase
    if remain == 0:
        print(total)
        exit()

# Optimized solution

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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
for (yen, num) in AB:
    if num <= M:
        ans += (yen * num)
        M -= num
    else:
        ans += (yen * M)
        print(ans)
        exit()

print(ans)
# 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], x[1]))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    for i in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)


# 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], x[1]))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    money += A*B
    ct += B
    if ct >= M:
        money -= (ct - M)*A
        break

print(money)
# Original solution
N, M = (int(x) for x in input().split())
a, b, b2, p = [], [], [], []
for i in range(N):
    o, t = (int(x) for x in input().split())
    a.append(o)
    b.append(t)
ans = 0
while M > 0:
    idx = a.index(min(a))
    n = b[idx]
    if M - n >= 0:
        ans += a[idx] * n
        M -= n
    else:
        ans += a[idx] * M
        M = 0
    del a[idx]
    del b[idx]
print(ans)



# Optimized solution
n, m = list(map(int, input().split()))
l = []
for _ in range(n): l.append([int(x) for x in input().split()])
l.sort()
s = cnt = 0
for a, b in l:
    if cnt + b < m:
        s += a*b
        cnt += b
    else:
        s += a * (m - cnt)
        break
print(s)
# Original solution
#!/usr/bin/python3
# abc121_c

"""
Energy Drink Collector
"""
test = False


def main():
    """
    とにかく安い方からM本になるまで買い続ける。
    """
    N, M = list(map(int, input().split()))
    l = []

    for _ in range(N):
        # 安い順に、値段だけのリストをつくる。[100, 100, 100, 110, 120, 120, ...]
        tempA, tempB = list(map(int, input().split()))
        l.extend([tempA] * tempB)

    # 安い順に並べる
    l.sort()
    if test:
        print(l)

    # 買う。
    cost = sum(l[0:M])

    # 合計金額を出力
    print(cost)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/python3
# abc121_c

"""
Energy Drink Collector
"""
test = False


def main():
    """
    とにかく安い方からM本になるまで買い続ける。
    """
    N, M = list(map(int, input().split()))
    l = []
    bottle = 0
    cost = 0

    for _ in range(N):
        # [値段, 在庫本数] の2xNリストをつくる。
        l.append(list(map(int, input().split())))

    # 安い順に並べる
    l.sort()
    # 安い店の在庫を全部買って、M本を超えたら中断

    for i in range(N):
        bottle += l[i][1]
        cost += l[i][0] * l[i][1]
        # 買いすぎた分を返品
        if bottle >= M:
            cost -= (bottle - M) * l[i][0]
            break

    # 合計金額を出力
    print(cost)


if __name__ == '__main__':
    main()
# Original solution
n,m=list(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
    break
print(doll)

# Optimized solution
n,m=list(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()
# Original solution
n,m = list(map(int,input().split()))
a = []
b = []
for _ in range(n):
    a1,b1 = list(map(int,input().split()))
    a.append(a1)
    b.append(b1)
ans = 0
cnt = 0
flag = 1
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i] < a[i-1]:
            a[i],a[i-1] = a[i-1],a[i]
            b[i],b[i-1] = b[i-1],b[i]
            flag = 1
for i in range(n):
    flag = 1
    while b[i] > 0 and cnt < m:
        ans += a[i]
        cnt += 1
        b[i] -= 1
        flag = 0
    if flag:
        break
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
a = []
b = []
for _ in range(n):
    a1,b1 = list(map(int,input().split()))
    a.append(a1)
    b.append(b1)
c = sorted(zip(a,b))
ans = 0
for i in range(n):
    if m > c[i][1]:
        ans += c[i][0]*c[i][1]
        m -= c[i][1]
    else:
        ans += c[i][0]*m
        break
print(ans)
# Original solution
n,m=list(map(int,input().split()))
ab=[]
for i in range(n):
  a=list(map(int,input().split()))
  ab.append(a)
ab=sorted(ab, key=lambda x:x[0])

cnt,ans,j=0,0,0

while cnt<m:
  if ab[j][1]>=m-cnt:
    ans+=ab[j][0]*(m-cnt)
    cnt=m
  else:
    ans+=ab[j][0]*ab[j][1]
    cnt+=ab[j][1]
  j+=1
print(ans)


# Optimized solution
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]))
# Original solution
a, b = list(map(int, input().split()))

A = []
B = []
for i in range(a):
    c, d = list(map(int, input().split()))
    A.append(c)
    B.append(d)

ans = 0

for i in range(a*b + 1):
    j = A.index(min(A))
    if(b - B[j] >=0):
        ans += A[j] * B[j]
        b -= B[j]
        A[j] = 1000000
    else:
        ans += A[j] * b
        b = 0
    if(b == 0):
        break
    
print(ans)

# Optimized solution
a, b = list(map(int, input().split()))

A = []

for i in range(a):
    c= list(map(int, input().split()))
    A.append(c)

ans = 0

A.sort(key=lambda x:x[0])


for j in range(a+1):
    if(b - A[j][1] >=0):
        ans += A[j][0] * A[j][1]
        b -= A[j][1]
    else:
        ans += A[j][0] * b
        b = 0
    if(b == 0):
        break
    
print(ans)
# Original solution
n,m = list(map(int,input().split()))
drink = [list(map(int,input().split())) for _ in range(n)]
drink = sorted(drink, key=lambda drink:drink[0])
money = 0
total = 0
for i in range(n):
  if total+drink[i][1]<m:
    total += drink[i][1]
    money += drink[i][1]*drink[i][0]
  else:
    money += drink[i][0]*(m-total)
    print(money)
    exit()

# Optimized solution
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda ab:ab[0])

ans = 0
total = 0
for i in range(n):
  num = m - total
  if ab[i][1]<num:
    total += ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    total += num
    ans += num*ab[i][0]
    break
print(ans)
# Original solution
N,M=list(map(int, input().split()))
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
AB.sort()
count=0
summary=0
for i in range(N):
  for j in range(AB[i][1]):
    summary+=AB[i][0]
    count+=1
    if count==M:
      print(summary)
      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()
count=0
summary=0
for i in range(N):
  for j in range(AB[i][1]):
    summary+=AB[i][0]
    count+=1
    if count==M:
      print(summary)
      break
  else:
    continue
  break
# Original solution
var = list(map(int, input().split()))
N = var[0]
M = var[1]
 
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))
C = list(zip(A,B))
C = sorted(C)
A, B = list(zip(*C))
 
index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[i]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)

# Optimized solution
N, M = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
C = list(zip(A,B))
C = sorted(C)
A, B = list(zip(*C))
index = 0
count = 0
sum = 0
for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)
# Original solution
n, m = list(map(int, input().split()))
money = 0
li = []

for i in range(n):
    li.append(list(map(int, input().split())))
li.sort()

while 0 < m:
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)


# Optimized solution
n, m = list(map(int, input().split()))
money = 0
li = []

for i in range(n):
    li.append(list(map(int, input().split())))
li.sort()

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)
# Original solution
from operator import itemgetter

n, m = list(map(int, input().split()))
money = 0
li = sorted([list(map(int, input().split())) for _ in range(n)])

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)



# Optimized solution
n, m = list(map(int, input().split()))
money = 0
li = [list(map(int, input().split())) for _ in range(n)]
li.sort()

for j in range(n):
    shop = li[j]
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

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

A_list=[]
B_list=[]
for i in range(N):
    A, B = list(map(int,input().split()))
    A_list.append(A)
    B_list.append(B)

cost = 0
total_num = 0
num = 0
while True:
    index = A_list.index(min(A_list))
    num = B_list[index]
    if M > num:
        total_num += num
        cost += min(A_list)*num
        A_list.pop(index)
        B_list.pop(index)
        M -= num
    else:
        cost += min(A_list)*M
        break

print(cost)

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

AB_list=[]

for i in range(N):
    A, B = list(map(int,input().split()))
    AB_list.append([A, B])

AB_list = sorted(AB_list)
cost = 0
num = 0
for AB in AB_list:
    num = AB[1]
    if M > num:
        cost += AB[0]*num
        M -= num
    else:
        cost += AB[0]*M
        break

print(cost)
# 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)

R,S=M,0
while R!=0:
    mloc=A.index(min(A))
    AA=A.pop(mloc)
    BB=B.pop(mloc)
    if BB>=R:
        S+=AA*R;R=0
    else:
        S+=AA*BB;R-=BB
print(S)



# Optimized solution
N,M=list(map(int, input().split()))
A,B=[],[]
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x:x[0])
R,S=M,0
for a in A:
    if a[1]>=R:
        S+=a[0]*R;R=0
    else:
        S+=a[0]*a[1];R-=a[1]
    if R==0: break
print(S)
# Original solution
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N, M = list(map(int, input().split()))

    AB = [0] * N
    for i in range(N):
        AB[i] = list(map(int, input().split()))

    AB = sorted(AB)

    have = 0
    price = 0
    while M != have:
        AB[0][1] -= 1
        price += AB[0][0]
        have += 1

        if AB[0][1] == 0:
            del AB[0]


    print(price)

main()

# Optimized solution
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N, M = list(map(int, input().split()))

    AB = [0] * N
    for i in range(N):
        AB[i] = list(map(int, input().split()))

    AB = sorted(AB)

    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()
# Original solution
from operator import itemgetter

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

A_list  = []


for _ in range(N):
    A, B = list(map(int, input().split()))
    A_list.append([A, B])

A_list.sort(key=itemgetter(0))


dp = [0]*(M+1)

for i in range(1, M+1):

    for j in range(len(A_list)):
        if A_list[j][1]>0:
            A_list[j][1]-=1
            break
    
    dp[i] = dp[i-1]+A_list[j][0]

print((dp[M]))

# Optimized solution
import sys

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

L = []
for _ in range(N):
    A,B = list(map(int, input().split()))
    L.append([A,B])

L = sorted(L, key=lambda x: x[0])

sum = 0
for i in range(len(L)):
    l = L[i]
    if l[1]<M:
        M = M - l[1]
        sum = sum + l[0]*l[1]
    else:
        sum = sum + l[0]*M
        print(sum)
        sys.exit()      

print(sum)
# Original solution
import sys
N,M = list(map(int,input().split()))
A = []
B = []
for i in range(N):
    tmp_a,tmp_b = list(map(int,input().split()))
    A.append(tmp_a)
    B.append(tmp_b)
sum_A,sum_B = 0,0
while(M-sum_B)>0:
    min_index = A.index(min(A))
    if (M-sum_B) > B[min_index]:
        sum_A += min(A)*B[min_index]
        sum_B += B[min_index]
        A.pop(min_index)
        B.pop(min_index)
    else:
        sum_A += min(A)*(M-sum_B)
        print(sum_A)
        sys.exit()
        

# Optimized solution
import sys
N,M = list(map(int,input().split()))
List =[]
for i in range(N):
    tmp_a,tmp_b = list(map(int,input().split()))
    List.append([tmp_a,tmp_b])
List.sort()
sum_a,sum_b = 0,0
for i in range(N):
    if M-sum_b > List[i][1]:
        sum_a += List[i][0]*List[i][1]
        sum_b += List[i][1]
    else:
        sum_a += List[i][0]*(M-sum_b)
        sum_b += M-sum_b
        print(sum_a)
        sys.exit()
# Original solution
N, M = 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()))

index_list = []
a = A.copy()
for i in range(N):
    index_list.append(a.index(min(a)))
    a[a.index(min(a))] = 10 ** 9

sum = 0
num = 0
for i in index_list:
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            sum += A[i]
            num += 1
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]


# Optimized solution
N, M = 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()))

AB = list(zip(A, B))
AB.sort()
A, B = list(zip(*AB))

sum = 0
num = 0
for i in range(N):
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            num += 1
            sum += A[i]
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]