CodeEff/ECCO huggingface dataset:
# Original solution
n,m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
money = 0
drink = 0
for a,b in ab:
  money += a*b
  drink += b
  if drink >= m:
    money -= (drink-m) * a
    break
print(money)

# Optimized solution
n,m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
money = 0
drink = 0
for a,b in ab:
    if drink+b <= m:
        drink += b
        money += a*b
    else:
        money += (m-drink) * a
        drink = m
    if drink == m: break
print(money)
# 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 b <= m:
        ans += a*b
        m -= b
    elif b > m:
        ans += m * a
        break
print(ans)

# Optimized 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 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())))
li = [list(map(int,input().split())) for i in range(N)]

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])

print((sum(li3[0:M])))

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])
    if len(li3)>M:
        break
print((sum(li3[0:M])))
# Original solution
n,m = list(map(int, input().split()))
A = []
B = []
ans = 0
for n in range(n):
    a,b = list(map(int,input().split()))
    A.append(a)
    B.append(b)
    
while(m > 0):
    minA = min(A)
    if B[A.index(minA)] >= m:
        ans += minA*m
    else:
        ans += minA*B[A.index(minA)]
    m = m - B[A.index(minA)]
    
    B.pop(A.index(minA))
    A.pop(A.index(minA))
    
print(ans)

# Optimized solution
import itertools

n,m = list(map(int, input().split()))
AB = []
ans = 0
for n in range(n):
    a,b = list(map(int,input().split()))
    AB.append([a,b])
AB.sort()
A,B = list(zip(*AB))
A,B = list(A), list(B)

i = list(_ for _ in itertools.accumulate(B) if _ <= m)
if i == []:
    ans = A[0]*m
else:
    B = B[:len(i)] + [m-i[-1]]
    A = A[:len(B)]

    ans = sum([a*b for a,b in zip(A,B)])
print(ans)
# Original solution
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab)
cost=[]
for i in range(n):
  cost+=[ab[i][0]]*ab[i][1]
print((sum(cost[0:m])))

# Optimized solution
n,m=list(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)
# Original solution
n, m = list(map(int, input().split()))
l = [0 for _ in range(n)]
for i in range(n):
    l[i] = list(map(int, input().split()))
l_sort = sorted(l)
ans = 0
drink = 0
for j in range(n):
    cnt_lim = l_sort[j][1]
    cnt = 0
    while cnt < cnt_lim:
        ans += l_sort[j][0]
        cnt += 1
        drink += 1
        if drink == m:
            print(ans)
            exit()

# Optimized solution
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n, m = list(map(int, input().split()))
    dd = defaultdict(int)
    for _ in range(n):
        a, b = list(map(int, input().split()))
        dd[a] += b
    dd_sort = sorted(list(dd.items()), key=lambda x: x[0])
    ans = 0
    r = m
    for cost, num in dd_sort:
        if r >= num:
            ans += cost * num
            r -= num
        else:
            ans += cost * r
            break
    print(ans)
if __name__ == '__main__':
    main()
# Original solution
n,m = list(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
    if m >= 0:
        res += a*b
    else:
        m += b
        res += a*m
        break
print(res)

# Optimized solution
n,m = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i 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)
# Original solution
n,m = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i 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)

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


# Optimized solution
n,m = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort()
res = 0
for a,b in AB:
    res += a*min(b,m)
    m -= b
    if m < 0:
        break 
print(res)
# Original solution
N,M = list(map(int, input().split()))
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = list(map(int, input().split()))
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for i in range(N):
    for j in range(AB[i][1]):
        if count < M:
            total += AB[i][0]
            count += 1
        else:
            break
                                                                                                                    
print(total)


# Optimized solution
N,M = list(map(int, input().split()))
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = list(map(int, input().split()))
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for AB_ in AB:
    num = min(M, AB_[1])
    total += AB_[0]*num
    M -= num
print(total)
# Original solution
# -*- coding: utf-8 -*-
import bisect

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

price_list = []
stock_list = []
for i in range(N):
    A, B = list(map(int, input().split()))
    index = bisect.bisect_left(price_list, A)
    price_list.insert(index, A)
    stock_list.insert(index, B)

ans = 0
rest = M
for i in range(N):
    if stock_list[i] < rest:
        ans += price_list[i] * stock_list[i]
        rest -= stock_list[i]
    else:
        ans += rest * price_list[i]
        break

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
from operator import itemgetter


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

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


def main():
    b = sorted(a, key=itemgetter(0))
    m = 0
    cost = 0
    for i in range(N):
        if (m + b[i][1]) <= M:
            m += b[i][1]
            cost += (b[i][0] * b[i][1])
        else:
            cost += (b[i][0] * (M-m))
            return cost
    return cost


print((main()))
# Original solution
B = [float('inf')]*(10 ** 5)
A = [float('inf')]*(10 ** 5)
def main():
    accum = 0
    cost = 0
    N, M = list(map(int, input().split()))
    for i in range(N):
        A[i], B[i] = list(map(int, input().split()))
    while accum < M:
         index = A.index(min(A))
         Aind = A.pop(index)
         Bind = B.pop(index)
         if accum + Bind > M:
             cost += Aind * (M - accum)
             accum = M
         else:
             accum += Bind
             cost += Aind * Bind
    print(cost)

main()


# Optimized solution
from operator import itemgetter
A = []

def main():
    accum = 0
    cost = 0
    N, M = list(map(int, input().split()))
    for i in range(N):
        A.append(list(map(int, input().split())))
    B = sorted(A, key = itemgetter(0))
    while accum < M:
         eB = B.pop(0)
         if accum + eB[1] > M:
             cost += eB[0] * (M - accum)
             accum = M
         else:
             accum += eB[1]
             cost += eB[0] * eB[1]
    print(cost)

main()
# Original solution
N,M = list(map(int, input().split()))
shop = []
for i in range(N):
    a,b = list(map(int, input().split()))
    shop.append([a,b])

shop.sort(reverse=True)
ans = 0
while M > 0:
    a,b = shop.pop()
    tmp = min(b,M)
    ans += tmp * a
    M -= tmp
print(ans)


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

shop.sort()
ans = 0
for i in range(N):
    if M <= 0:
        break
    tmp = min(shop[i][1],M)
    ans += tmp * shop[i][0]
    M -= tmp
print(ans)
# Original solution
n, m = list(map(int, input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
total = [0] * (n + 1)
ans = 0

# 安い店から選ぶ方法が最適
shop = [tuple(map(int, input().split())) for _ in range(n)]
shop.sort()

for i in range(1, n + 1):
    a_i, b_i = shop[i - 1]
    # 累積和を作っておく
    # b[i]: i番目の店まで利用した際に購入できる栄養ドリンクの最大本数
    # total[i]: i番目の店まで利用した際に支払うお金の最大値
    b[i] = b[i - 1]
    total[i] = total[i - 1]
    b[i] += b_i
    total[i] += a_i * b_i

    # a[i]: i番目の店の栄養ドリンクの単価
    a[i] = a_i

for i in range(1, n + 1):
    if m <= b[i]:
        m = m - b[i - 1]
        # 足りない分を追加で計算
        ans = total[i - 1] + a[i] * m
        break
print(ans)

# Optimized solution
n, m = list(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)
# Original solution
n, m = list(map(int, input().split()))
info = [list(map(int, input().split())) for _ in range(n)]
info.sort()
ans = 0
for i in range(n):
    if m >= info[i][1]:
        m -= info[i][1]
        ans += info[i][0]*info[i][1]
    else:
        ans += info[i][0]*m
        m = 0
    if m == 0:
        break

print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
info = [list(map(int, input().split())) for _ in range(n)]
info.sort()
ans = 0
for i in range(n):
    if m >= info[i][1]:
        m -= info[i][1]
        ans += info[i][0]*info[i][1]
    else:
        ans += info[i][0]*m
        break

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

# Optimized solution
n, m = list(map(int, input().split()))
c=[[0 for i in range(2)] for i in range (n)]
for i in range(n):
    c[i][0],c[i][1] = list(map(int, input().split()))
c.sort()
price=0
i=0
while(m>0):
    if(m>c[i][1]):
        price+=c[i][0]*c[i][1]
        m-=c[i][1]
    else:
        price+=c[i][0]*m
        m=0
    i+=1
print(price)
# Original solution
def actual(N, M, AB):
    count = 0
    payment = 0

    while count < M:
        AB = [x for x in AB if x[1] > 0]
        m = min(AB, key=lambda x: x[0])

        payment += m[0]
        m[1] -= 1
        count += 1

    return payment

N, M = list(map(int, input().split()))
AB = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  AB.append([a, b])
  
print((actual(N, M, AB)))

# Optimized solution
def actual(N, M, AB):
    payment = 0

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

    for price, stock in shop_order_by_price_desc:
        if stock >= M:
            # 端数があるときは、残りの必要分だけ買えばよい
            return payment + (price * M)
        else:
            # 端数がないなら買い切る
            M -= stock
            payment += price * stock


N, M = list(map(int, input().split()))
AB = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    AB.append([a, b])

print((actual(N, M, AB)))
# Original solution
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(n)]

ab.sort()

AB=[[ab[i][0]]*ab[i][1] for i in range(n)]
A=[]
for i in AB:
    A+=i
ans=0

for i in range(m):
    ans+=A[i]
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
B=0
cnt=0
for a,b in ab:
    B+=b
    if B<m:
        ans+=a*b
        cnt+=b
    else:
        ans+=a*(m-cnt)
        print(ans)
        exit()
# Original solution
from operator import itemgetter

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

ab.sort(key=itemgetter(0))

result = 0
for e in ab:
  count = min(m, e[1])
  result += e[0] * count
  m = max(m-count, 0)
print(result)

# Optimized solution
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)
# Original solution
n,m=list(map(int,input().split()))
c=0;d={}
for _ in[0]*n:
 a,b=list(map(int,input().split()))
 if not a in list(d.keys()):
  d[a]=0
 d[a]+=b
for k in sorted(d.keys()):
 if d[k] < m:
  c+=k*d[k]
  m-=d[k]
 else:
  c+=k*m
  m=0
 if m == 0:break
print(c)

# Optimized solution
import sys;n,m=input().split();m=int(m);a=[];i=n=c=0;a=sorted(tuple(map(int,e.split()))for e in sys.stdin)
while m>0:c+=a[i][0]*a[i][1];m-=a[i][1];i+=1
print((c+m*a[~-i][0]))
# Original solution
n, m = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

def bubble_sort(lst):
    for i in reversed(list(range(len(lst)))):
        for j in range(i):
            if lst[j][0] > lst[j + 1][0]:
                lst[j], lst[j + 1] = lst[j + 1], lst[j]

bubble_sort(a)
purchase_price = 0

for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)

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

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


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

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

res = 0
cnt = 0
for a, b in AB:
    tmp = M - cnt
    if tmp <= b:
        res += a * tmp
        break
    res += a * b
    cnt += b

print(res)


# Optimized solution
import sys

N, M = list(map(int, input().split()))
AB = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N)]

AB.sort()

res = 0
for a, b in AB:
    if M > b:
        M -= b
        res += a * b
    else:
        res += a * M
        break
print(res)
# Original solution
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in list(ABdict.keys()):
        ABdict[A] += B
    else:
        ABdict[A] = B

dct = sorted(ABdict.items())
ls = []
for pricenumber in dct:
    for i in range (pricenumber[1]):
        ls.append(pricenumber[0])

print((sum(ls[:M])))

# Optimized solution
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in list(ABdict.keys()):
        ABdict[A] += B
    else:
        ABdict[A] = B

dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)
# Original solution
### coding: UTF-8
import sys

head = sys.stdin.readline()
[n, m] = [int(x) for x in head.split(" ")]

amount = 0

# 店の件数分読み込み
rows = [sys.stdin.readline() for _ in range(n)]
rows.sort(key=lambda x: int(x.split(" ")[0]))
for row in rows:
    [ai, bi] = [int(x) for x in row.strip().split(" ")]
    # 購入可能な最大数まで買う
    x = bi if m >= bi else m
    amount += ai * x
    m -= x
    if m == 0:
        break

print(amount)


# Optimized solution
### coding: UTF-8
import sys

amount = 0

# 安い店から買える最大数分買う。ほしい個数を超えてる場合はほしい個数だけ
[n, m] = [int(x) for x in sys.stdin.readline().split(" ")]
for row in sorted([sys.stdin.readline() for _ in range(n)], key=lambda x: int(x.split(" ")[0])):
    [ai, bi] = [int(x) for x in row.strip().split(" ")]
    x = bi if m >= bi else m
    amount += ai * x
    m -= x
    if m == 0:
        break

print(amount)
# Original solution
from sys import stdin
def main():
  from builtins import int, list, map, min
  readline = stdin.readline
  n, m = list(map(int, readline().split()))
  data = [list(map(int, readline().split())) for _ in range(n)]
  data.sort(key = lambda x: x[0])
  purchased = 0
  amount = 0
  for v in data:
    t = min(m - purchased, v[1])
    amount += t * v[0]
    purchased += t
    if purchased == m:
      break
  print(amount)
main()

# Optimized solution
from sys import stdin
def main():
  from builtins import int, list, map, min
  readline = stdin.readline
  n, m = list(map(int, readline().split()))
  data = [list(map(int, readline().split())) for _ in range(n)]
  data.sort(key = lambda x: x[0])
  purchased = 0
  amount = 0
  for a, b in data:
    t = min(m - purchased, b)
    amount += t * a
    purchased += t
    if purchased == m:
      break
  print(amount)
main()
# 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)
ans = 0
tmp = 0
while tmp < M:
    num = min([M-tmp,B[A.index(min(A))]])
    tmp += num
    ans += num * min(A)
    ind = A.index(min(A))
    del A[ind]
    del B[ind]
print(ans)

# Optimized solution
from operator import itemgetter
N,M = list(map(int,input().split()))
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        i = i-1
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i][0]*(pon - M)
    print(ans)
# Original solution
N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(N)]
A = []
B = []
for i in range(N):
	A.append(L[i][0])
	B.append(L[i][1])
cost = 0
num = 0
while True:
	if num == M:
		break
	cost = cost + min(A)*min(B[A.index(min(A))], M - num)
	num = num + min(B[A.index(min(A))], M - num)
	B.pop(A.index(min(A)))
	A.remove(min(A))
print(cost)
exit()

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

A = []
B = []
for i in range(N):
	A.append(L[i][0])
	B.append(L[i][1])
num = 0
cost = 0
i = 0
while num < M:
	cost = cost + A[i]*min(B[i], M - num)
	num = num + min(B[i], M - num)
	i = i + 1

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

sorted_items = sorted(
    ab,
    key=lambda x: x[0]
)
cost = 0
bought = 0
for c, stock in sorted_items:
    for s in range(1, stock + 1):
        bought += 1
        cost += c
        if bought == m:
            print(cost)
            exit()


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

shops = sorted(
    ab,
    key=lambda x: x[0]
)
paid = 0
for cost, stock in shops:
    num = min(m, stock)
    paid += num * cost
    m = m - num
    if m == 0:
        break
print(paid)
# Original solution
N,M = list(map(int,input().split()))
A = []
B = []
count = 0
sum = 0

for i in range(N):
  a,b = list(map(int,input().split()))
  A.append(a)
  B.append(b)
 
while(count < M):
  min_price = min(A)
  min_index = A.index(min_price)
  A_buy_num = B[min_index]
  if((count + A_buy_num)  <= M):
   count += A_buy_num
   sum += (A.pop(min_index))*(B.pop(min_index))
  else: #(count + A_buy_num)  > M
   rest_num = M - count 
   count += rest_num
   sum += (A.pop(min_index))*(rest_num)
   break

print(sum)
  


# Optimized solution
N,M = list(map(int,input().split()))
AB = []
count = 0
sum = 0

for i in range(N):
  a,b = list(map(int,input().split()))
  s = [a,b]
  AB.append(s)
  
AB.sort()
i = 0
while(1):
  if(count >= M):
    break  
  if((count + AB[i][1]) <= M):
   sum += AB[i][0]*AB[i][1]
   count += AB[i][1]
  else:
    rest = M - count
    sum += AB[i][0]*rest
    break
  i += 1

print(sum)
# Original solution
li = list(map(int,input().split()))
num = li[0]
want = li[1]
cost = []
max_num = []
total_num = 0
total_cost = 0
for i in range(num):
	a = list(map(int,input().split()))
	cost.append(a[0])
	max_num.append(a[1])
while want > total_num:
	min_cost = min(cost)
	m = cost.index(min_cost)
	if total_num + max_num[m] > want:
		total_cost += (want - total_num) * cost[m]
		total_num = want
	else:
		total_cost += max_num[m] * cost[m]
		total_num += max_num[m]
		cost.remove(cost[m])
		max_num.remove(max_num[m])
print(total_cost)

# Optimized solution
n,m = list(map(int,input().split()))
li = [list(map(int,input().split())) for _ in range(n)]
li = sorted(li, key=lambda x:x[0])
cnt = 0
coin = 0
for a,b in li:
    c_cnt = cnt + b
    if c_cnt < m:
        cnt += b
        coin += a*b
    else:
        cnt += b-(c_cnt - m)
        coin += a*(b-(c_cnt-m))
        break
print(coin)
# Original solution
N, M = list(map(int, input().split()))
A = []
B = []
sumcost = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
k = 0
while k < M:
    min_index = A.index(min(A))
    B[min_index] -= 1
    sumcost += A[min_index]
    if B[min_index]<1:
        del A[min_index]
        del B[min_index]
    k += 1



print(sumcost)

# Optimized solution
N, M = list(map(int, input().split()))
A = []
sumcost = 0
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
k = 0
A.sort()
while k < M:
    sumcost += A[0][0]
    A[0][1] -= 1
    if A[0][1]<1:
        A.pop(0)
    k += 1



print(sumcost)
# Original solution
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
for i in range(M):
    if M-k>A[0][1]:
        sumcost += A[0][0]*A[0][1]
        k += A[0][1]
        A.pop(0)
    else:
        sumcost += A[0][0]*(M-k)
        break

print(sumcost)

# Optimized solution
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)
# Original solution
N, M = list(map(int, input().split()))
A = list([0] * N)   # A yen
B = list([0] * N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

require = M
price = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    a = A.pop(minidx)
    b = B.pop(minidx)
    if(require >= b):
#        print("buy = {}, price = {}".format(b, a))
        price = price + a * b
        require = require - b
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + a * require
        require = 0

print(price)


# Optimized solution
YEN = 0
NUM = 1

N, M = list(map(int, input().split()))
shop = list([])
for i in range(N):
    a, b = list(map(int, input().split()))
    shop.append([a, b])
shop.sort()

require = M
price = 0
minidx = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
#    print("idx = {}, num = {}, price = {}".format(minidx, shop[minidx][NUM], shop[minidx][YEN]))
    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + shop[minidx][YEN] * require
        require = 0

print(price)