CodeEff/ECCO huggingface dataset:
# 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()))
    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)

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

# Optimized solution
N, M = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(N)]
S.sort()
ans = 0
k = M
for i in range(N):
  if k == 0:
    break
  elif S[i][1] <= k:
    k -= S[i][1]
    ans += S[i][0] * S[i][1]
  else:
    ans += S[i][0] * k
    k = 0
print(ans)
# Original solution
N,M=list(map(int,input().split()))
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB)
K=M
c=-1
while K>0:
    K-=AB[c+1][1]
    c+=1
S=[(AB[c][1]+K)*AB[c][0]]
for k in range(c):
    S.append(AB[k][0]*AB[k][1])
print((sum(S)))

# Optimized solution
N,M=list(map(int,input().split()))
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB)
c=-1
while M>0:
    M-=AB[c+1][1]
    c+=1
S=[(AB[c][1]+M)*AB[c][0]]
for k in range(c):
    S.append(AB[k][0]*AB[k][1])
print((sum(S)))
# Original solution
import sys
input = sys.stdin.readline
n,m = list(map(int,input().split()))
d = {}
for i in range(n):
  a,b = list(map(int,input().split()))
  if a in list(d.keys()):
    d[a] += b
  else:
    d.setdefault(a,b)
l = list(d.keys())
l.sort()
count = 0
mon = 0
i = 0
while count < m:
  mon += l[i]*d[l[i]]
  count += d[l[i]]
  i += 1
i -= 1
if count > m:
  mon -= (count-m)*l[i]
print(mon)

# Optimized solution
import sys
input = sys.stdin.readline
n,m = list(map(int,input().split()))
l = []
for i in range(n):
  a,b = list(map(int,input().split()))
  l.append([a,b])
l.sort()
i = 0
count = 0
money = 0
while count < m:
  count += l[i][1]
  money += l[i][0]*l[i][1]
  i += 1
i -= 1
if count > m:
  money -= (count-m)*l[i][0]
print(money)
# Original solution
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
cost = 0

for A, B in sorted(AB):
    if M >= B:
        cost += A*B
        M -= B
        if M == 0:
            break
    else:
        cost += A*M
        break

print(cost)


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

for A, B in sorted(AB):
    if M >= B:
        cost += A*B
        M -= B
    else:
        cost += A*M
        break

print(cost)
# Original solution
N,M = list(map(int,input().split()))
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
pay = 0
for i in range(N):
    if cnt+A[i][1]<=M:
        pay += A[i][0]*A[i][1]
        cnt += A[i][1]
    else:
        m = M-cnt
        pay += A[i][0]*m
        break
print(pay)        

# Optimized solution
N,M = list(map(int,input().split()))
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
for i in range(N):
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:
        d = M-cnt
        cost += a*d
        break
print(cost)
# Original solution
li_a = []
ans = 0
N,M = list(map(int,input().split()))
for i in range(N):
    a,b = list(map(int,input().split()))
    li_a +=[[a,b]]
li_a.sort()
for i in range(N):
    if li_a[i][-1] >= M:
        ans += M * li_a[i][0]
        print(ans)
        break
    else:
        ans += li_a[i][-1] * li_a[i][0]
        M -= li_a[i][-1]





# Optimized solution
n,m = list(map(int,input().split()))
ab = [0] * n
ans = 0
for i in range(n):
    a,b = list(map(int,input().split()))
    ab[i]= (a,b)
ab.sort()

for i in range(n):
    if m > ab[i][1]:
        m -= ab[i][1]
        ans += ab[i][0] * ab[i][1]
    else:
        ans += ab[i][0] * m
        break

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

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

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=B[0][0]
    for i in B:#どの店で買うか
        if Min>=i[0]:
            Min=i[0]
            l=k
        k+=1

    for x in range(B[l][1]):#何個かえるか

        m+=1
        if M==X+m:#max
            money+=m*Min
            print(money)
            break


    money+=m*Min
    X+=m

    B.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数


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

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

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数
for a,b in B:
    if(M<=0):
        break
    if(b<=M):
        money+=a*b
    else:
        money+=M*a
    M-=b
print(money)
# Original solution
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

while canNum > 0 and not currentStoreHasMoreCans:
    currentStoreHasMoreCans = True
    minCostIndex = costs.index(min(costs))
    if canNum >= maxCanNumbers[minCostIndex]:
        totalPrice = totalPrice + costs[minCostIndex] * maxCanNumbers[minCostIndex]
        canNum = canNum - maxCanNumbers[minCostIndex]
    else:
        totalPrice = totalPrice + costs[minCostIndex] * canNum
        canNum = 0
    currentStoreHasMoreCans = False
    costs[minCostIndex] = 1000000001

print(totalPrice)

# Optimized solution
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

costs, maxCanNumbers = (list(x) for x in zip(*sorted(zip(costs, maxCanNumbers))))

for i in range(storeNum):
    if canNum >= maxCanNumbers[i]:
        totalPrice = totalPrice + costs[i] * maxCanNumbers[i]
        canNum = canNum - maxCanNumbers[i]
        if canNum is 0:
            break
    else:
        totalPrice = totalPrice + costs[i] * canNum
        canNum = 0    
        break

print(totalPrice)
# Original solution
# C
n, m = list(map(int, input().split()))
ab = [[int(i) for i in input().split()] for i in range(n)]
ab.sort(key=lambda x: x[0])
index = 0
ans = 0
while m > 0 and index <= n:
    if ab[index][1] <= m:
        ans += ab[index][0] * ab[index][1]
        m -= ab[index][1]
    else:
        ans += ab[index][0] * m
        m = 0
    index += 1
print(ans)

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

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

cost = 0
for i in range(n):
    value = ab[i][0]
    num = ab[i][1]
    if num > m:
        cost += value * m
        break
    else:
        cost += value * num
        m -= num
print(cost)
# Original solution
n, m  = list(map(int, input().split()))
a, b = [], []
for i in range(n):
    x, y = list(map(int, input().split()))
    a.append([x, i])
    b.append([y, i])
a.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    i = a[idx][1]
    for j in range(len(b)):
        if b[j][1] == i:
            kosuu = b[j][0]
    if kosuu <= m:
        ans += kosuu * a[idx][0]
        m -= kosuu
        idx += 1
    else:
        ans += m * a[idx][0]
        m = 0
print(ans)


# Optimized solution
n, m  = list(map(int, input().split()))
arr = []
for i in range(n):
    a, b = list(map(int, input().split()))
    arr.append([a, b])
arr.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    ans += arr[idx][0] * min(arr[idx][1], m)
    m -= min(arr[idx][1], m)
    idx += 1
print(ans)
# Original solution
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)
cnt = 0
ans = 0

for e in AB:
    if cnt + e[1] < M:
        ans += e[0] * e[1]
        cnt += e[1]
    else:
        ans += e[0] * (M - cnt) 
        break

print(ans)

# Optimized solution
import sys

N, M = list(map(int, sys.stdin.readline().split()))
AB = [None] * N
for i in range(N):
    AB[i] = list(map(int, sys.stdin.readline().split()))

AB.sort()
cnt = 0
ans = 0

for a,b in AB:
    if cnt + b < M:
        ans += a * b
        cnt += b
    else:
        ans += a * (M - cnt) 
        break

print(ans)
# Original solution
import itertools
import math
import fractions
import functools
import copy
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])

yen = 0
amount = 0
index = 0
for i in range(n):
    if amount < m:
        yen += ab[i][0] * ab[i][1]
        amount += ab[i][1]
        index = i
    else: break
b = 0
for i in range(index):
    b += ab[i][1]
print((yen - ab[index][1]*ab[index][0] + ab[index][0]*(m-b)))


# Optimized solution
def main():
    # n = int(input())
    n, m = list(map(int, input().split()))
    # a = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

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

    cost = 0
    temp_i = 0
    ab.sort(key=lambda x: x[0])
    for i in range(n):
        cost += ab[i][0] * ab[i][1]
        m -= ab[i][1]
        if m <= 0:
            temp_i = i
            break

    if m == 0:
        print(cost)
    elif m < 0:
        cost += ab[temp_i][0] * m
        print(cost)


if __name__ == '__main__':
    main()
# Original solution
N, M = list(map(int, input().split()))
A = [0]*N
for i in range(N):
  A[i] = [0,0]
  A[i][0],A[i][1] = list(map(int, input().split()))
A.sort()
sum = 0
for a in A:
  if a[1]<M:
    sum += a[0]*a[1]
    M -= a[1]
  else:
    sum += a[0]*M
    print(sum)
    exit()



# Optimized solution
def solve():
    N, M = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(N)]
    A.sort()
    ans = 0
    cnt = 0
    for a in A:
        if cnt + a[1] <= M:
            ans += a[1]*a[0]
            cnt += a[1]
        else:
            ans += a[0]*(M-cnt)
            break
    return ans
print((solve()))
# Original solution
N, M = list(map(int, input().split()))

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

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

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

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

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

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

money = 0
cnt = 0
for i in range(N):
    if cnt + A[i][1] < M: 
        money += A[i][0]*A[i][1]
        cnt += A[i][1]
    else: 
        money += A[i][0]*(M-cnt)
        print(money)
        break
# Original solution
# -*- coding:utf-8 -*-

class Shop():
    def __init__(self, yen, num):
        self.yen = yen  # ドリンクの単価
        self.num = num  # 販売している個数


def solve():
    N, M = list(map(int, input().split(" ")))
    A, B = [], []
    shops = []
    for i in range(N):
        a, b = list(map(int, input().split(" ")))
        A.append(a)
        B.append(b)
        shops.append(Shop(a, b))
    
    shops = sorted(shops, key=lambda x: x.yen)

    ans = 0
    rest_count = M
    for i in range(N):
        if rest_count <= shops[i].num:
            ans += shops[i].yen * rest_count
            break
        ans += shops[i].yen * shops[i].num
        rest_count -= shops[i].num
    
    print(ans)


if __name__ == "__main__":
    solve()

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

class Shop():
    def __init__(self, v, n):
        self.value = v
        self.zaiko = n

def solve():
    N, M = list(map(int, input().split()))
    shops = []
    for i in range(N):
        a, b = list(map(int, input().split()))
        shops.append(Shop(a, b))
    
    shops.sort(key=lambda x: x.value)

    rest = M
    ans = 0
    for i in range(N):
        if shops[i].zaiko <= rest:
            ans += shops[i].value * shops[i].zaiko
            rest -= shops[i].zaiko
        else:
            ans += shops[i].value * rest
            break
    
    print(ans)


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

total = 0
while len(A) > 0:
    i = A.index(min(A))
    if B[i] == M:
        total += A[i] * B[i]
        break
    elif B[i] > M:
        total += A[i] * M
        break
    else:
        total += A[i] * B[i]
        M -= B[i]
        A.pop(i)
        B.pop(i)
print(total)

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

shop.sort()

total = 0
for i in range(len(shop)):
    if shop[i][1] == M:
        total += shop[i][0] * shop[i][1]
        break
    elif shop[i][1] > M:
        total += shop[i][0] * M
        break
    else:
        total += shop[i][0] * shop[i][1]
        M -= shop[i][1]
print(total)
# Original solution
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))
c = []
for i in range(n):
    a, b = list(map(int, input().split()))
    c += [a]*min(b,m)
c.sort()
print((sum(c[:m])))

# Optimized solution
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))
ab = []
ans = 0
for i in range(n):
    a, b = list(map(int, input().split()))
    ab.append((a,b))
ab = sorted(ab)
for c, d in ab:
    if m >= d:
        ans += c*d
        m -= d
    else:
        ans += c*m
        break
print(ans)
# Original solution
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    k, l = list(map(int, input().split()))
    a.append(k)
    b.append(l)
sum = 0
money = 0
index = a.index(min(a))
while sum + b[index]< m:
    sum += b[index]
    money += a[index] * b[index]
    del a[index]
    del b[index]
    index = a.index(min(a))
money += (m - sum) * a[index]
print(money)


# Optimized solution
n, m = list(map(int, input().split()))
a = []
b = []
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
sum = 0
money = 0
index = 0
while sum + data[index][1]< m:
    sum += data[index][1]
    money += data[index][0] * data[index][1]
    del data[index]
money += (m - sum) * data[index][0]
print(money)
# Original solution
a,b=list(map(int,input().split()))
e=[]
for i in range(a):
    c,d=list(map(int, input().split()))
    e+=[c]*d
e.sort()
print((sum(e[:b])))

# Optimized solution
a,b=list(map(int,input().split()))
e=[]
for i in range(a):
    c,d=list(map(int, input().split()))
    e+=[[c,d]]
e.sort()
a=i=j=0
while i < b:
    a+=(e[j][0]*e[j][1])
    i+=e[j][1]
    j+=1
print((a-((i-b)*e[j-1][0])))
# Original solution
n, m = list(map(int, input().split()))
sum = 0
money = 0
A = list()
B = list()
for i in range(n):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))
for i in range(n):
    index = A.index(min(A))
    if(B[index] >= m - sum):
        money += A[index] * (m - sum)
        sum = m
        break
    else:
        sum += B[index]
        money += A[index]*B[index]
    del A[index]
    del B[index]
print(money)

# Optimized solution
n, m = list(map(int, input().split()))
sum = 0
money = 0
list_ab = list()
for i in range(n):
    list_ab.append(list(map(int, input().split())))
list_ab = sorted(list_ab)
for i in range(n):
    if(list_ab[i][1] >= m - sum):
        money += list_ab[i][0] * (m - sum)
        break
    else:
        sum += list_ab[i][1]
        money += list_ab[i][0]*list_ab[i][1]
print(money)
# Original solution
# -*- coding: utf-8 -*-
N,M = list(map(int,input().split()))

res_dict = {0:0}
for _ in range(N):
    #M本になるまでは買い続け、M本より多くなった場合は、価格の高いものから
    a,b = list(map(int,input().split()))
    cur_max_price = max(res_dict.keys())
    if sum(res_dict.values()) - M < 0 or a < cur_max_price:
        #追加操作
        if a in res_dict:
            res_dict[a] += b
        else:
            res_dict[a] = b
    decrease = sum(res_dict.values()) - M
    while decrease > 0:
        max_price = max(res_dict.keys())
        if decrease < res_dict[max_price]:
            res_dict[max_price] -= decrease
            break
        else:
            decrease -= res_dict[max_price]
            res_dict.pop(max_price)

print((sum([k * v for k,v in list(res_dict.items())])))


# Optimized solution
# -*- coding: utf-8 -*-
N,M = list(map(int,input().split()))

l = [list(map(int,input().split())) for _ in range(N)]
l = sorted(l, key=lambda x:x[0])
a_cnt = 0
b_cnt = 0
for a,b in l:
    if b <= M:
        b_cnt += b
        M -= b
        a_cnt += a*b
    elif b > M and M > 0:
        b_cnt += M
        a_cnt += a*M
        break
    else:
        break
print(a_cnt)
# Original solution
n, m = list(map(int, input().split()))
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
for item in a:
    if pm + item[1] >= m:
        print((s + item[0] * (m - pm)))
        break
    else:
        pm += item[1]
        s += item[0] * item[1]


# Optimized solution
n, m = list(map(int, input().split()))
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    tmp = pm + item[1]
    if tmp > m_minus_1:
        print((s + item[0] * (m - pm)))
        break
    else:
        pm = tmp
        s += item[0] * item[1]
# Original solution
n, m = list(map(int, input().split()))
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
b = sorted(a)
pm = s = 0
m_minus_1 = m - 1
for item in b:
    tmp = pm + item[1]
    if tmp > m_minus_1:
        print((s + item[0] * (m - pm)))
        break
    else:
        pm = tmp
        s += item[0] * item[1]


# Optimized solution
n, m = list(map(int, input().split()))
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print((s + item[0] * (m - pm + item[1])))
        break
    else:
        s += item[0] * item[1]
# Original solution
from operator import itemgetter

n, m = list(map(int, input().split()))
shops = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    shops.append((a, b))

shops = sorted(shops, key=itemgetter(0))
drink = [[a] * b for (a, b) in shops]
drink = sum(drink, [])
# print(drink)
answer = sum(drink[:m])
print(answer)

# Optimized solution
from operator import itemgetter

n, m = list(map(int, input().split()))
shops = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    shops.append((a, b))

shops = sorted(shops, key=itemgetter(0))
rest = m
cost = 0
for a, b in shops:
    if rest > b:
        cost += a * b
        rest -= b
    else:
        cost += a * rest
        break

print(cost)
# Original solution
N, M = list(map(int, input().split()))
lis = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  for l in range(b):
    lis.append(a)
lis.sort()
total = 0
for i in range(M):
  total = total + lis[i]
print(total)  

# Optimized solution
N, M = list(map(int, input().split()))
lis = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  lis.append((a, b))
def eval(data):
  return data[0]
lis.sort(key=eval)
total = 0
num = 0
mark = 0
for i in range(N):
  num = num + lis[i][1]
  total = total + lis[i][0]*lis[i][1]
  if num > M:
    mark = i
    total = total - lis[i][0]*lis[i][1]
    num = num - lis[i][1]
    break
total = total + (M - num)*lis[mark][0]
print(total)
# Original solution
n, m = list(map(int, input().split()))
a = []
b = []
al = []
ans = 0
for i in range(n):
    al.append(list(map(int, input().split())))

for i in range(n):
    a.append(al[i][0])
    b.append(al[i][1])

ans = 0
while(m > 0):
    if m > b[a.index(min(a))]:
        m -= b[a.index(min(a))]
        ans += a[a.index(min(a))]*b[a.index(min(a))]
        b.pop(a.index(min(a)))
        a.pop(a.index(min(a)))
    else :
        ans += a[a.index(min(a))]*m
        break
print(ans)

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

a =[]
for i in range(n):
    a.append(ab[i][0])

b = []
for i in range(n):
    b.append(ab[i][1])

x = 0 #本数
y = 0 #金額

while m > x:
    if b[a.index(min(a))] > 0:
        y += min(a)
        b[a.index(min(a))] -= 1
        x += 1
    else:
        del b[a.index(min(a))]
        del a[a.index(min(a))]
        continue

print(y)


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

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

cnt = 0
price = 0
i = 0
while cnt < m:
    price += ab[i][0] * ab[i][1]
    cnt += ab[i][1]
    if cnt > m:
        price -= ab[i][0] * (cnt - m)
        break
    i += 1

print(price)
# Original solution
# ABC 121 C

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

arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))

arr.sort()

sum = 0

for i in range(N):
    if arr[i][1] < M:
        sum += arr[i][0] * arr[i][1]
        M -= arr[i][1]
    else:
        sum += arr[i][0] * M
        break

print(sum)


# Optimized solution
def resolve():
  n, m = list(map(int, input().split()))
  l = []
  for i in range(n):
    a, b = list(map(int, input().split()))
    l.append([a, b])
  l.sort()
  ans = 0
  for ab in l:
    if ab[1] < m:
      m -= ab[1]
      ans += ab[0] * ab[1]
    else:
      ans += ab[0] * m
      m = 0
      break
  print(ans)
  return

if __name__ == "__main__":
  resolve()
# Original solution
N, M = list(map(int, input().split()))
AB = [[] for i in range(N)]
for i in range(N):
    AB[i] = list(map(int, input().split()))

remain_drink = M
price = 0
while remain_drink > 0:
    min_ind = -1
    min_price = 10 ** 10
    for i in range(N):
        if AB[i][0] < min_price:
            min_price = AB[i][0]
            min_ind = i

    if AB[min_ind][1] <= remain_drink:
        price += AB[min_ind][0] * AB[min_ind][1]
        remain_drink -= AB[min_ind][1]
    else:
        price += AB[min_ind][0] * remain_drink
        remain_drink = 0
    AB[min_ind][0] = 10 ** 10

print(price)



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

AB = sorted(AB)

remain_drink = M
price = 0
i = 0
while remain_drink > 0:
    if AB[i][1] <= remain_drink:
        price += AB[i][0] * AB[i][1]
        remain_drink -= AB[i][1]
    else:
        price += AB[i][0] * remain_drink
        remain_drink = 0
    i += 1
print(price)