CodeEff/ECCO huggingface dataset:
# Original solution
# ABC121C - Energy Drink Collector
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
ans = 0
for i in lst:
    while i[1] > 0 and m > 0:
        ans += i[0]
        i[1] -= 1
        m -= 1
print(ans)

# Optimized solution
# ABC121C - Energy Drink Collector
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    lst = sorted(list(map(int, input().split())) for _ in range(n))
    ans = 0
    for i in lst:
        while i[1] > 0 and m > 0:
            ans += i[0]
            i[1] -= 1
            m -= 1
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
# ABC121C - Energy Drink Collector
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    lst = sorted(list(map(int, input().split())) for _ in range(n))
    ans = 0
    for i in lst:
        while i[1] > 0 and m > 0:
            ans += i[0]
            i[1] -= 1
            m -= 1
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# ABC121C - Energy Drink Collector
def main():
    N, M, *AB = list(map(int, open(0).read().split()))
    AB = list(zip(*[iter(AB)] * 2))
    AB.sort()
    ans = 0
    for a, b in AB:
        while b > 0 and M > 0:
            ans += a
            b -= 1
            M -= 1
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N, M = list(map(int, input().split(" ")))
stores = dict()
p = 10000000000

for i in range(N):
    if p==1 and stores[p] >= M:
      break
    Ai, Bi = list(map(int, input().split(" ")))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
while True:
    if p in stores:
        if M <= stores[p]:
            price += p * M
            break
        else:
            price += p * stores[p]
            M -= stores[p]
    p += 1
print(price)


# Optimized solution
N, M = list(map(int, input().split(" ")))
stores = []

for i in range(N):
    Ai, Bi = list(map(int, input().split(" ")))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)
# Original solution
def mergesort(a, left, right):
    if left + 1 < right:
        mid = int((left + right)/2)
        mergesort(a, left, mid)
        mergesort(a, mid, right)
        merge(a, left, mid, right)
    return a

def merge(a, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = [a[left + i] for i in range(n1)]
    R = [a[mid + i] for i in range(n2)]
    L.append(1e10)
    R.append(1e10)
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1

store_num, drink_num = [int(i) for i in input().split(" ")]
a_list = []
for i in range(store_num):
    a, b = [int(i) for i in input().split(" ")]
    for j in range(b):
        a_list.append(a)
b_list = mergesort(a_list, 0, len(a_list))
ans = 0
for i_ in range(drink_num):
    ans += b_list[i_]
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
a = []
for i in range(n):
    i,j = (list(map(int, input().split())))
    a += [[i,j]]
a = sorted(a)
count = 0
value = 0
for (i,j) in a:
    if count + j >= m:
        value += (m - count) * i
        break
    else:
        value += i * j
        count += j
print(value)
# Original solution
N, M = list(map(int, input().split()))
A_list = []
for i in range(N):
    A, B = list(map(int, input().split()))
    A_list += [A for i in range(B)]
A_list.sort()
value = sum(A_list[0:M])
print(value)

# Optimized solution
N, M = list(map(int, input().split()))
AB_list = [list(map(int, input().split())) for i in range(N)]
AB_list.sort()
ans, cnt = 0, 0
for a, b in AB_list:
    ans += a*b
    cnt += b
    if cnt > M:
        ans = ans-(a*(cnt-M))
        break
print(ans)
# Original solution
n,m=list(map(int,input().split(" ")))
al=[0 for i in range(n)]
bl=[0 for i in range(n)]
for i in range(n):
    al[i],bl[i]=tuple(map(int,input().split(" ")))
have=0
yen=0
while have<m:
    k=al.index(min(al))
    pri=al.pop(k)
    num=bl.pop(k)
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)

# Optimized solution
n,m=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
have=0
yen=0
i=0
l.sort(key=lambda x: x[0])
while have<m:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)
# Original solution
# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

ans = 0
while M > 0:
    if AB[0][1] == 0:
        AB = AB[1:]

    ans += AB[0][0]
    M -= 1

    AB[0][1] -= 1

print(ans)



# Optimized solution
# coding: utf-8

# import sys
# input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)
# Original solution
# coding: utf-8

# import sys
# input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)



# Optimized solution
# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

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 += [a]
  B += [b]
AA = []
BB = []
while True:
  le = len(A)
  if le == 0:
    break
  else:
    for i in range(le):
      mini = min(A)
      if A[i] == mini:
        AA += [A[i]]
        BB += [B[i]]
        del A[i]
        del B[i]
        break
rest = M
cost = 0
while True:
  if rest - BB[0] <= 0:
    cost += rest * AA[0]
    break
  else:
    rest -= BB[0]
    cost += AA[0] * BB[0]
    del AA[0]
    del BB[0]
print(cost)

# Optimized solution
N,M = list(map(int,input().split()))
ab = []
for i in range(N):
  ab += [list(map(int,input().split()))]
ab.sort()
rest = M
cost = 0
while True:
  if rest - ab[0][1] <= 0:
    cost += rest * ab[0][0]
    break
  else:
    rest -= ab[0][1]
    cost += ab[0][0] * ab[0][1]
    del ab[0]
print(cost)
# Original solution
N,M = list(map(int,input().split()))
ab = []
for i in range(N):
  ab += [list(map(int,input().split()))]
ab.sort()
rest = M
cost = 0
while True:
  if rest - ab[0][1] <= 0:
    cost += rest * ab[0][0]
    break
  else:
    rest -= ab[0][1]
    cost += ab[0][0] * ab[0][1]
    del ab[0]
print(cost)

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

# Optimized solution
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: x[0])
num = 0
ansum = 0
for i in range(n):
    if num + l[i][1] < m:
        ansum += l[i][0] * l[i][1]
        num += l[i][1]
    else:
        ansum += l[i][0] * (m - num)
        break
print(ansum)
# Original solution
N, M = list(map(int, input().split()))
Di = []
for i in range(N):
    d = list(map(int, input().split()))
    Di.append(d)
Di.sort(key=lambda x: x[0])

yen = 0
num = 0
for d in Di:
    if num + d[1] >= M:
        yen += (M - num) * d[0]
        break
    num += d[1]
    yen += d[0] * d[1]
print(yen)

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

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

cost = 0
remain = M
for a in Ai:
    if remain == 0:
        break
    buy_num = min(a[1], remain)
    cost += a[0] * buy_num
    remain -= buy_num
print(cost)
# Original solution
f = lambda : list(map(int,input().split()))
n,m = f()
ll = sorted([list(f()) for _ in range(n)])
ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break
print(ans)

# Optimized solution
f=lambda:list(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)
# Original solution
N,M=list(map(int,input().split()))
k=M
s=0
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
while k>0:
  for i in range(N):
    if k>A[i][1]:
      s+=A[i][0]*A[i][1]
      k=k-A[i][1]
    else:
      s+=A[i][0]*k
      k=0
print(s)

# Optimized solution
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
s=0 #本数
t=0 #値段
for i in range(N):
  s+=A[i][1]
  if M>s:
    t+=A[i][0]*A[i][1]
  else:
    over=s-M
    t+=A[i][0]*A[i][1]-A[i][0]*over
    break
print(t)
# Original solution
N, M = list(map(int, input().split()))
a, b = [], []
ans = 0
INF = float('inf')
for n in range(N):
    tmp1, tmp2 = list(map(int, input().split()))
    a.append(tmp1)
    b.append(tmp2)

count = 0
while count < M:
    mindex = a.index(min(a))
    buycount = min(b[mindex], M - count)
    count += buycount
    ans += a[mindex]*buycount
    a[mindex] = INF
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
ans = 0
drink = M
a, b = [], []
INF = float('inf')
for n in range(N):
    a.append(list(map(int, input().split())))
a.sort()
for i in a:
    if drink > i[1]:
        ans += i[0] * i[1]
        drink -= i[1]
    else:
        ans += i[0] * drink
        break
print(ans)
# Original solution
def main():
    N, M = list(map(int, input().split()))
    D = [tuple(map(int, input().split())) for _ in range(N)]
    D.sort()
    ans = 0
    while M > 0:
        a, b = D.pop(0)
        ans += a * min(M, b)
        M -= min(M, b)
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    N, M = list(map(int, input().split()))
    D = [tuple(map(int, input().split())) for _ in range(N)]
    D.sort()
    ans = 0
    i = 0
    while M > 0:
        a, b = D[i]
        ans += a * min(M, b)
        M -= min(M, b)
        i += 1
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N, M = list(map(int,input().split()))
L = [list(map(int, input().split())) for i in range(N)]
L.sort(key=lambda x: x[0])
c = 0
for i in range(N):
    if M <= L[i][1]:
        print((c + L[i][0] * M))
        exit()
    else:
        M -= L[i][1]
        c += L[i][0] * L[i][1]


# Optimized 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])
ans = 0
for i in range(N):
    if M > AB[i][1]:
        ans += AB[i][0] * AB[i][1]
        M -= AB[i][1]
    else:
        ans += AB[i][0] * M
        break
print(ans)
# Original solution
N, M = list(map(int, input().split()))
A = []
B = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    A.append(x1)
    B.append(y1)
    
yen = 0
num = 0
while num < M:
    a  = min(A)
    ind = A.index(a)
    
    if num + B[ind] <= M:
        yen += a * B[ind]
        num += B[ind]
        del A[ind]
        del B[ind]
    else:
        yen += a * (M - num)
        break
print(yen)

# Optimized solution
N, M = list(map(int, input().split()))
S = []
C = 0
cost = 0
for i in range(N):
  a, b = list(map(int, input().split())) 
  S.append((a, b))
S.sort()
for i in range(N):
  if S[i][1] + C < M:
    C += S[i][1]
    cost += S[i][0] * S[i][1]
  else:
    cost += (M-C) * S[i][0]
    break
print(cost)
# Original solution
n, m = (int(_) for _ in input().split())
ab_list = [[int(i) for i in input().split()] for i in range(n)]

ab_list = sorted(ab_list)

buy = 0
money = 0
j = 0
lst = []

for i in range(n):
    lst.append(ab_list[n - i - 1][1])
    b_sum = sum(lst)

while (buy < m):
    buy += ab_list[j][1]
    money += ab_list[j][0] * ab_list[j][1]
    j += 1

print((money-(ab_list[j-1][0]*(buy-m))))


# Optimized solution
n, m = (int(_) for _ in input().split())
ab_list = [[int(i) for i in input().split()] for i in range(n)]

ab_list = sorted(ab_list)

buy = 0
money = 0
j = 0


while (buy < m):
    buy += ab_list[j][1]
    money += ab_list[j][0] * ab_list[j][1]
    j += 1

print((money-(ab_list[j-1][0]*(buy-m))))
# Original solution
N,M = list(map(int,input().split(' ')))
#A = []
#B = []
Drinks = []
for i in [0]*N:
	a,b = list(map(int,input().split(' ')))
	#A.append(a)
	#B.append(b)
	Drinks+=[a]*b
Drinks.sort()
 
print((sum(Drinks[:M])))


# Optimized solution
N,M = list(map(int,input().split(' ')))
D = []
for i in [0]*N:
	a,b = list(map(int,input().split(' ')))
	D.append([a,b])

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

ans = 0
for c, s in D:
	if s < M:
		M -= s
		ans += c * s
	else:
		ans += M * c
		break
print(ans)
# Original solution
import copy
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

def merge(list):
    mid = len(list)
    if mid > 1:
        left = merge(list[:(mid//2)])
        right = merge(list[(mid//2):])
        list = []
        while len(left) != 0 and len(right) != 0:
            if left[0][0] < right[0][0]:
                list.append(left.pop(0))
            else:
                list.append(right.pop(0))
        if len(left) != 0:
            list.extend(left)
        elif len(right) != 0:
            list.extend(right)
    return list

num_of_drink, total_fee = 0, 0
List = copy.copy(merge(List))

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

# Optimized solution
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)
# Original 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
for i in range(n):
    a, b = AB[i]
    if b >= m:
        ans += a*m
        break
    else:
        ans += a*b
    m -= b
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
for a, b in AB:
    if b <= m:
        ans += a*b
        m -= b
    else:
        ans += a*m
        m = 0
    if m == 0:
        break
print(ans)
# Original solution
n, m = list(map(int, input().split()))
stores = []
for i in range(n):
    store = input().split()
    stores.append([int(store[i]) for i in range(2)])
stores.sort()

drinks = 0
cost = 0
for store in stores:
    if drinks + store[1] <= m:
        drinks += store[1]
        cost += store[0]*store[1]
    elif drinks + store[1] > m:
        cost += (m - drinks)*store[0]
        break
print(cost)

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

drinks = 0
cost = 0
for store in stores:
    if drinks + store[1] <= m:
        drinks += store[1]
        cost += store[0]*store[1]
    elif drinks + store[1] > m:
        cost += (m - drinks)*store[0]
        break
print(cost)
# Original solution
n,m = list(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)

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

ans = 0
for a,b in ab:
  ans += a*min(m,b)
  m -= min(m,b)
  if m == 0: break
print(ans)
# Original solution
N, M = list(map(int, input().split()))

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

quantitys = 0
total = 0

for i in range(N):
    quantity = 0
    x = 0
    for ii in range(S[i][1]):
        if quantitys<M:
            quantitys += 1
            quantity += 1
    x += quantity * S[i][0]
    total += x

print((str(total)))



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

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

quantitys = 0
total = 0

for i in range(N):
    # 【根本註】この for 文の中がソースコードの変更点となります。
    # ここまでのコードで、二次元配列 S に「エナジードリンクが安い順」に
    # 金額と本数のセットを格納できているわけですから、あとは「その店で何本買えばよいか？」
    # を計算し、for 文を使わずに普通の数式ベースで金額・本数の計算を行ってしまうのが正しい方法となります。
    
    #【根本註】必要な本数 M から「今何本購入しているか」を表す quantitys を引くことで、
    # 「あと何本購入する必要があるか」を表す変数 need を計算します。
    need = M - quantitys

    #【根本註】この変数 need：「あと何本必要か」が、今参照している店の在庫本数：S[i][1] 以上ならば、
    # その店の在庫を全部購入することができるはずです。（在庫を全部買うと、残りが 0 本ちょうどか 1 本以上に
    # なります）
    if(need - S[i][1])>=0:
        # 【根本註】そのため、この場合は S[i][1] 本のエナジードリンクを S[i][0] 円で買ったものとして、
        # quantitys には S[i][1] を足し、金額の合計 total には S[i][0] * S[i][1] の 金額 × 本数 の合計額を
        # 足してしまいます。こうすることで、従来は購入する本数分だけ回していた for 文の処理を全て削減し、
        # 1 本の数式に落とし込むことができ、処理にかかる時間を非常に大きく削減することが可能になるのです。
        quantitys += S[i][1]
        total += S[i][0] * S[i][1]

    #【根本註】一方で、変数 need：「あと何本必要か」が、今参照している店の在庫本数：S[i][1] より少なければ、
    # その店では need 本だけ購入すれば、必要な本数ちょうどに揃えることが可能になります。
    else:
        # 【根本註】同様に、この場合は need 本のエナジードリンクを S[i][0] 円で買ったものとして、
        # quantitys には need を足し、金額の合計 total には S[i][0] * need の 金額 × 本数 の合計額を
        # 足してしまいます。
        quantitys += need
        total += S[i][0] * need

    #【根本註】ここまでの処理を終えた段階で、もし M （必要本数）から quantities（購入済の本数）を引いた値が
    # ゼロになったならば、必要な本数を買い揃えることができたということになりますから、ループを終了します。
    if M-quantitys == 0:
        break

print((str(total)))
# Original solution
n,m,*l=list(map(int,open(0).read().split()))
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m=max(m-t,0)
  if not m:
    break
print(ans)

# Optimized solution
n,m,*l=list(map(int,open(0).read().split()))
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m-=t
  if m<=0:
    print(ans)
    break
# Original solution
#n=int(input())
n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(n)]

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

#print(l)
money=0
count=0
for i in range(n):
    a=l[i][0];b=l[i][1]
    if (m-count)>b :
        count+=b
        money+=a*b
    else:
        money+=a*(m-count)
        count+=(m-count)
        break
print(money)


# Optimized solution
#n=int(input())
n,m=list(map(int,input().split()))
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
l=[]
for i in range(n):
    a,b=list(map(int,input().split()))
    l.append([a,b])

l.sort(key=lambda x: x[0])
count=0;cost=0
for i in range(n):
    a,b=l[i][0],l[i][1]
    if count+b>=m:
        cost+=a*(m-count)
        break
    else:
        cost+=a*b
        count+=b
print(cost)
# Original solution
n,m = list(map(int,input().split(' ')))
cost = 0
count = 0

mlist = list()
for i in range(n):
  mlist.append(list(map(int,input().split(' '))))
  mlist.sort(key=lambda x: x[0])

for i in range(n):
  ablist = mlist[i]
  if count+ablist[1] <= m:
    count += ablist[1]
    cost += ablist[0]*ablist[1] 
  else:
    for j in range(ablist[1]):
      count += 1
      if count <= m:
        cost += ablist[0]
      else:
        break_t = True
        break
    if break_t:
      break
print(cost)



# Optimized solution
n,m = list(map(int,input().split(' ')))
cost = 0
count = 0

mlist = list()
for i in range(n):
  mlist.append(list(map(int,input().split(' '))))
mlist.sort(key=lambda x: x[0])

for i in range(n):
  ablist = mlist[i]
  if count+ablist[1] <= m:
    count += ablist[1]
    cost += ablist[0]*ablist[1] 
  else:
    for j in range(ablist[1]):
      count += 1
      if count <= m:
        cost += ablist[0]
      else:
        break_t = True
        break
    if break_t:
      break
print(cost)
# Original solution
n,m = list(map(int,input().split()))
a = []
b = []
ans = 0
for i in range(n):
  aa, bb = list(map(int,input().split()))
  a.append(aa)
  b.append(bb)
ans = 0
mini = 10000000000
while(1):
  for i in range(n):
    if a[i] < mini:
      mini = a[i]
      index = i
  ans = ans + a[index]*min(m,b[index])
  m = m - min(m,b[index])
  if m == 0:
    break
  a.pop(index)
  b.pop(index)
  n = n - 1
  mini = 10000000000
  
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
a = []
b = []
raw = []
ans = 0
for i in range(n):
  raw.append(list(map(int,input().split())))
raw.sort(key=lambda x:x[0])
for i in range(n):
  ans = ans + raw[i][0] * min(raw[i][1],m)
  m = m - min(raw[i][1],m)
  if m == 0:
    break
print(ans)
# Original solution
n,m  =list(map(int,input().split()))
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
mon = 0
lm.sort(key = lambda x:x[0])

while s + lm[0][1] < m:
    s += lm[0][1]
    mon += lm[0][1]*lm[0][0]
    lm = lm[1::]
while s < m:
    s += 1
    mon += lm[0][0]
    lm[0][1] -= 1
    
print(mon)

# 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 i in AB:
  if i[1] >= M:
    Ans += i[0] * M
    break
  else:
    Ans += i[0] * i[1]
    M -= i[1]
 
print(Ans)
# Original solution
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

remaining = M
cost = 0
while True:
  store = stores[getCheapest()]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    bought = store[1]
    store[1] = 0
    cost += store[0] * bought
    remaining -= bought

print(cost)

# Optimized solution
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 安さ順にソート
stores.sort(key = lambda s: s[0])

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)
# Original solution
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()

ans = 0
for a, b in AB:
  if M == 0: break
  if M >= b:
    ans += a * b
    M -= b
  else:
    ans += a * M
    M = 0
    break
print(ans)

# Optimized solution
n,m = list(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)