Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.
There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.
What is the minimum amount of money with which he can buy M cans of energy drinks?
It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N, M \leq 10^5
 - 1 \leq A_i \leq 10^9
 - 1 \leq B_i \leq 10^5
 - B_1 + ... + B_N \geq M

-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

-----Output-----
Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

-----Sample Input-----
2 5
4 9
2 4

-----Sample Output-----
12

With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.

Difficulty: introductory

Starter code:

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

cnt=0
gokei=0
for ab in AB:
	if M-cnt>ab[1]:
		gokei+=ab[1]*ab[0]
		cnt+=ab[1]
	else:
		gokei+=(M-cnt)*ab[0]
		cnt+=M-cnt
	
	if cnt==M:
		print(gokei)
		return

n, m = list(map(int, input().split()))

s = [tuple(map(int, input().split())) for _ in range(n)]
s.sort()

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

print(ans)


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

AB.sort(key=lambda x : x[0])
ans = 0
for AB in AB:
    if M <= AB[1]:
        ans += M * AB[0]
        break
    else:
        ans += AB[0] * AB[1]
        M -= AB[1]
print(ans)

n,m = list(map(int,input().split()))

C={}
S1=[]
for i in range(n):
    a,b = list(map(int,input().split()))
    S1.append(a)
    if a in C:
        C[a]+=b
    else:
        C[a]=b
S=list(set(S1))
S.sort()

ans=0
for s in S:
    # print(S,C,ans)
    if m<C[s] :
        ans+=m*s
        break
    else:
        ans+=C[s]*s
        m-=C[s]

print(ans)




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

ans, l = 0, m
for a, b in ab:
    if b > l:
        ans += l*a
        break
    ans += b*a
    l -= b
print(ans)

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
    ans += ab[i][0]*ab[i][1]
    cnt += ab[i][1]
    i += 1
print(ans - (cnt - m)*ab[i-1][0])

n,m=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)

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
A = sorted(AB,key=lambda x:x[0])
ans = 0

for i in range(N):
    buy = min(M,A[i][1])
    ans += buy * A[i][0]
    M -= buy
print(ans)

def resolve():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        a = list(map(int, input().split()))
        A.append(a)
    ans = 0
    for i, j in sorted(A, key=lambda x: x[0]):
        if j >= M:
            ans += M * i
            print(ans)
            return
        ans += i * j
        M -= j
resolve()


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

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

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

ans = 0
count = 0
flag = 0
for i in sorted_l:
    if flag == 1:
        break
    for j in range(i[1]):
        if count >= M:
            flag = 1
            break
        ans += i[0]
        count += 1
print(ans)

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for a, b in ab:
    ans += a * min(b, m)
    m -= b
    if m <= 0:
        break
print(ans)

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


N, M = map(int, input().split())
AB = []

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

AB.sort()

i = 0
ans = 0

while M > 0:
  A, B = AB[i]
  if B <= M:
    ans += A * B
    M -= B
  else:
    ans += A * M
    M = 0
  i += 1

print(ans)

N,M=list(map(int,input().split()))
A=dict()
ans=0
A=[list(map(int,input().split()))for i in range(N)]
A.sort()
for i in range(N):
    if M>A[i][1]:
        M-=A[i][1]
        ans+=A[i][0]*A[i][1]
    else:
        ans+=A[i][0]*M
        break
print(ans)


n,m=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)
    return

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 range(n):
    if m >= ab[i][1] :
        ans += ab[i][0]*ab[i][1]
        m = m -ab[i][1]
    elif 0 < m < ab[i][1] :
        ans += m*ab[i][0]
        break
print(ans)


import sys
input = sys.stdin.readline # for speed up
#sys.setrecursionlimit(10**9)

n,m=list(map(int,input().split()))
a=[""]*n
for ii in range(n):
  a[ii]=list(map(int,input().split()))
a.sort()
r=0
for ii in range(n):
  if a[ii][1]>=m:
    r+=a[ii][0]*m
    print(r)
    return
  else:
    r+=a[ii][0]*a[ii][1]
    m-=a[ii][1]


n,m=map(int,input().split())
a=[]
cnt=0
for i in range(n):
    k,j=input().split()

    a.append([int(k),int(j)])
a=sorted(a)
for i in range(n):
    if a[i][1]>=m:
        cnt+=a[i][0]*m
        break
    else:
        cnt+=a[i][0]*a[i][1]
        m-=a[i][1]
print(cnt)

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

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

count = 0
money = 0

for x in shop:
  count += x[1]
  money += x[0] * x[1]
  if count >= m:
    excess = count - m
    money -= x[0] * excess
    break
    
print(money)

N,M = list(map(int,input().split()))
price = [[] for i in range(N)]
for i in range(N):
    a,b = list(map(int,input().split()))
    price[i] = [a,b]
price.sort()
#print(price)
m = 0
money = 0
for i in range(N):
    if m + price[i][1] < M:
        money += price[i][0] * price[i][1]
        m += price[i][1]
    else:
        money += price[i][0] * (M-m)
        break
print(money)


def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    data = sorted([Input() for _ in range(n)])
    amount = 0
    for x, y in data:
        get1 = min(y, m)
        m = m - get1
        amount += get1 * x
        if m <= 0:
            return amount

print(main())

n, m = list(map(int, input().split()))
stores = [list(map(int, input().split())) for _ in range(n)]
sorted_sotres = sorted(stores, key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_sotres:
    if number > m:
        ans += cost * m
        break
    elif number == m:
        ans += cost * number
        break
    else:
        ans += cost * number
    m -= number
print(ans)


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

ans = 0
bought = 0
for a, b in AB:
    m = min(M - bought, b)
    bought += m
    ans += a * m
print(ans)

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)

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

AB.sort()
cost = 0
cnt = 0
i = 0
while(cnt<M):
  a, b = AB[i]
  if M-cnt<=b:
    cost += a * (M-cnt)
    cnt = M
    break
  cost += a * b
  cnt += b
  i += 1
ans = cost
print(ans)

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

sum = 0
mr = 0
ks = sorted(k)

for i in range(n):
    if ks[i][1] < (m-mr):
        sum += ks[i][0] * ks[i][1]
        mr += ks[i][1]

    else:
        sum += ks[i][0] * (m - mr)
        break

print(sum)


n,m = map(int,input().split())
s = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort()
for i in s:
    if m<i[1]:
        ans += m*i[0]
        break
    else:
        ans += i[0]*i[1]
        m -= i[1]
print(ans)

N,M = map(int,input().split())
X = sorted([list(map(int,input().split())) for n in range(N)])
G = 0
D = 0

for m in range(M):
  if D+X[m][1]<M:
    D+=X[m][1]
    G+=X[m][0]*X[m][1]
  else:
    G+=X[m][0]*(M-D)
    print(G)
    return

#a値段,b本数
#n軒,m本
n,m = list(map(int, input().split()))

ab_list = [list(map(int, input().split())) for _ in range(n)]
#print(ab_list)
ab_list.sort()
ans = 0
num = 0
for ab in ab_list:
    ans += ab[0]*ab[1]
    num += ab[1]
    if num >= m:
        i_stop=ab_list.index(ab)
        break
diff_num = num - m
ans -= diff_num * ab_list[i_stop][0]
print(ans)

n, m = list(map(int, input().split()))
lis = []
ans = 0

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

lis.sort()

for x in lis:
  a, b = x
  if m >= b:
    m -= b
    ans = ans + (a*b)
  else:
    ans = ans + (a*m)
    break
  
print(ans)


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

ans = 0
num = 0
for i in range(N):
  flag = False
  val = A[i][0]
  max_num = A[i][1]
  for j in range(max_num):
    ans += val
    num += 1
    if num == M:
      flag = True
      break
  if flag: break
    
print(ans)

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

ans = bought = 0
for a, b in AB:
    m = min(M - bought, b)
    bought += m
    ans += a * m
print(ans)


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

ans = 0
count = 0
for i in range(N):
    a, b = AB[i]

    if M - count <= b:
        c = M - count
        count += c
        ans += a * c
        break

    count += b
    ans += a * b

print(ans)

n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt < m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])

a = list(map(int,input().split()))
b = []
ans = 0
cnt = a[1]
for i in range(a[0]):
  c = list(map(int,input().split()))
  b.append(c)
b = sorted(b)
for i in b:
  if cnt == 0:
    break
  ans += i[0]*min(cnt,i[1])
  cnt -= min(cnt,i[1])
print(ans)
    
  
  



a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]

c=sorted(c,key=lambda x:x[0])
ans=0
for i in range(a):
    if b==0:
        break
    elif b>=c[i][1]:
        b-=c[i][1]
        ans+=c[i][1]*c[i][0]
    else:
        ans+=b*c[i][0]
        break
print(ans)

N, M = map(int, input().split())
d = dict()
shop = set()
ans = 0
for i in range(N):
  A, B = map(int, input().split())
  if A in d:
    d[A] += B
  else:
    d[A] = B
  shop.add(A)
shop = list(shop)
shop.sort()
for i in shop:
  if d[i] >= M:
    ans += (i * M)
    break
  else:
    ans += (i * d[i])
    M -= d[i]
print(ans)

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

ab = sorted(ab)

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

print(money)

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

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

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
        M = 0
    if M == 0:
        break

print(ans)

n,m=map(int,input().split())
l=[]

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

l.sort()
c=0
for a,b in l:
  c+=min(b,m)*a
  m=max(m-b,0)

print(c)

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

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

li.sort()

g=0
s=0

for i in range(N):
    if li[i][1]+s<M:
        s+=li[i][1]
        g+=li[i][1]*li[i][0]
    else:
        g+=(M-s)*li[i][0]
        print(g)
        return


N,M = map(int,input().split())
AB = []
money = 0
drinks = 0

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

AB.sort()

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

n,m = map(int,input().split())
dic = {}
for i in range(n):
    a,b = map(int,input().split())
    dic.setdefault(a,0)
    dic[a] += b
#print(dic)
nedan = sorted(dic)
#print(nedan)
ans = 0
for yen in nedan:
    if dic[yen] < m:
        #print(yen,dic[yen],m)
        ans += yen * dic[yen]
        m -= dic[yen]
    else:
        #print(yen,dic[yen],m)
        ans += yen * m
        break
print(ans)

N,M=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
List.sort()
res = 0
num = 0
i = 0
while num < M:
  if List[i][1] != 0:
    pass
  else:
    i +=1
  num += 1
  res += List[i][0]
  List[i][1] += -1
print(res)

n,m=map(int,input().split())
ab=[]
for i in range(n):
  a,b=map(int,input().split())
  ab.append([a,b])
ab.sort()
ans=0
t=m
for i in range(n):
  if ab[i][1]<t:
    ans+=ab[i][0]*ab[i][1]
    t-=ab[i][1]
  else:
    ans+=ab[i][0]*t
    print(ans)
    return

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  

n,m=input2()
AB=[input_array() for _ in range(n)]

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

for i in range(n):
	a= AB[i][0]
	b= AB[i][1]
	if b>m:
		ans+=a*m
		break
	elif b==m:
		ans+=a*b
		break
	else:
		ans+=a*b
	m-=b
print(ans)

N,M = map(int,input().split())
lsd = []
for i in range(N):
    lsd.append(list(map(int,input().split())))
lsd.sort(key=lambda x:x[0])
ans = 0
i = 0
while M != 0:
    if M >= lsd[i][1]:
        ans += lsd[i][0]*lsd[i][1]
        M -= lsd[i][1]
    else:
        ans += lsd[i][0]*M
        M = 0
    i += 1
print(ans)

N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])

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

print(ans)



N,M = map(int,input().split())
list = []
for _ in range(N):
  a,b = map(int,input().split())
  list.append([a,b])
list.sort()
ans = 0
for a,b in list:
  ans += min(b,M)*a
  M = max(0,M-b)
print(ans)

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

ab_sorted = sorted(ab, key=lambda x:(x[0], -x[1]))

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)
    return


n,m=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
c=0
d=0
for i in range(n):
    if c+a[i][1]<=m:
        c+=a[i][1]
        d+=a[i][0]*a[i][1]
    else:
        d+=(m-c)*a[i][0]
        break
print(d)

n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
sell=sorted(sell.items())
if m<=sell[0][1]:
  print(m*(sell[0][0]))
  return
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    return
  else:
    buy+=(lis[0])*(lis[1])

#C - Energy Drink Collector
N,M = map(int,input().split())
A_B = [tuple(map(int,input().split())) for _ in range(N)]

A_B = sorted(A_B, key = lambda x:x[1],reverse = True)
A_B = sorted(A_B, key = lambda x:x[0], reverse = False)

pay = 0
drink = M
for A, B in A_B:
    if drink <= B:
        pay += A*drink
        break
    else:
        pay += A*B
        drink -= B
print(pay)

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

ll.sort()

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

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

A = sorted(A.items(), key = lambda x:x[1])
ans = 0
num = 0
for i in range(N):
  flag = False
  max_num = B[A[i][0]]
  for j in range(max_num):
    ans += A[i][1]
    num += 1
    if num == M:
      flag = True
      break
  if flag: break
    
print(ans)

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

# 安い店から順に買う
# 安い順にsort => M本に達するまで前から順に買う
A = sorted([list(map(int, input().split())) for _ in range(N)])

num = 0
ans = 0
for i in range(N):
  flag = False
  val = A[i][0]
  max_num = A[i][1]
  for j in range(max_num):
    ans += val
    num += 1
    if num == M:
      flag = True
      break
  if flag: break
    
print(ans)

n,m=map(int,input().split())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
l.sort(key=lambda x:x[0])
ans=0
count=0
for i in range(n):
    k=min(m-count,l[i][1])
    count+=k
    ans+=k*l[i][0]
print(ans)

N,M=map(int,input().split())
A=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append([a,b])
    
A.sort()
S=0
for i,j in A:
    if M-j>=0:
        S+=i*j
        M-=j
    else:
        S+=M*i
        break
print(S)

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

@author: liang
"""

N, M = map(int, input().split())
drinks = list()
for i in range(N):
  a, b = 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)

N, M =map(int, input().split())
list1 = []
cost = 0
for i in range(N):
  A, B = map(int, input().split())
  list1.append((A, B))
list2 = sorted(list1, key= lambda x:x[0])
for i in range(N):
  if M >= list2[i][1]:
    M -= list2[i][1]
    cost += list2[i][0] * list2[i][1]
  else:
    break
cost += list2[i][0] * M
print(cost)

n,m=map(int, input().split())
alist=[list(map(int, input().split())) for l in range(n)]
alist.sort(key=lambda x:x[0])
ans=0
cnt=m
for i in range(n):
  if alist[i][1]<cnt:
    ans+=alist[i][0]*alist[i][1]
    cnt-=alist[i][1]
  else:
    ans+=cnt*alist[i][0]
    break
print(ans)

n,m = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(n)]
L = sorted(L, key=lambda x: x[0])
limit = m
ans = 0
for i in range(n):
  if limit <= 0: break
  ans += min(limit, L[i][1]) * L[i][0]
  limit -= L[i][1]
print(ans)

N,M = map(int,input().split())
drink = [list(map(int,input().split())) for _ in range(N)]
drink = sorted(drink)
ans = 0
for i in range(N):
   for j in range(drink[i][1]):
        ans += drink[i][0]
        M -= 1
        if M == 0:
            print(ans)
            return

N,M=map(int,input().split())
L=sorted([tuple(map(int,input().split())) for i in range(N)])
ans=0
for a,b in L:
    if M>b:
        ans+=a*b
        M-=b
    else:
        ans+=a*M
        break
print(ans)

n,m = map(int, input().split(" "))
a = sorted(list(map(int, input().split(" "))) for i in range(n))
total = 0
for i, j in a:
  if j < m:
    m -= j
    total += i * j
  else:
    total += i * m
    break
print(total)

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

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

n,m = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0
a = sorted(a, key=lambda x:x[0])
for i in range(n):
    if cnt + a[i][1] <m:
        ans += a[i][0]*a[i][1]
        cnt +=a[i][1]
    else:
        ans += a[i][0]*(m-cnt)
        break
print(ans)

from operator import itemgetter

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
#print(ab)
i = 0
ans = 0
while m >0:
  if ab[i][1]<=m:
    m -= ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    ans += ab[i][0]*m
    m = 0
  i+=1
print(ans)

N,M=list(map(int,input().split()))
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort(key = lambda x:x[0])
x,y = [list(i) for i in zip(*xy)]
nokori=M
ans=0
for i in range(N):
  ans+=x[i]*min(y[i],nokori)
  nokori-=y[i]
  if nokori<=0:
    break
print(ans)



import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = list(map(int, read().split()))
    X = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    X.sort()

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

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

n,m = list(map(int,input().split()))
x = [list(map(int,input().split())) for l in range(n)]
x = sorted(x)
count = m
p = 0
for i in x:
  if count >= i[1]:
    count -= i[1]
    p += i[0] * i[1]
  elif count ==0:
    break
  else:
    p += i[0] * count
    count = 0

print(p)


N, M = list([int(n) for n in input().split(" ")])
E = []
for i in range(N):
  tmp = input().split(" ")
  E.append({
    "price": int(tmp[0]),
    "count": int(tmp[1])
  })

E.sort(key=lambda e: e["price"])

totP = 0
totC = 0
for i in range(len(E)):
  if totC + E[i]["count"] >= M:
    totP += (M - totC) * E[i]["price"]
    break
  else:
    totC += E[i]["count"]
    totP += E[i]["price"] * E[i]["count"]

print(totP)


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

n,m=map(int,input().split())
l=[]
for _ in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
ans=0
for a,b in l:
  ans+=min(b,m)*a
  m=max(0,m-b)
print(ans)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-27 00:00:39 +0900
# LastModified: 2020-09-27 00:16:46 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    N, M = list(map(int, input().split()))
    path = []
    for _ in range(N):
        A, B = list(map(int, input().split()))
        path.append([A, B])
    path.sort(key=lambda x: x[0])
#    print(path)
    ans = [0, 0]  # (much, num)
    for p in path:
        if ans[1] + p[1] <= M:
            ans[0] = ans[0] + p[0]*p[1]
            ans[1] += p[1]

        else:
            num = M-ans[1]
            ans[0] = ans[0] + p[0]*num
            ans[1] = ans[1] + num
        if ans[1] == M:
            print((ans[0]))
            return
#        print(ans)


def __starting_point():
    main()

__starting_point()

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    AB = [LI() for _ in range(N)]
    AB.sort()

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

    print(ans)

def __starting_point():
    resolve()

__starting_point()

N, M = [ int(v) for v in input().split(" ") ]
d = []
for i in range(N):
  d.append([ int(v) for v in input().split(" ")])

total = 0
for v, n in sorted(d):
  if M > n:
    total += (v*n)
    M -= n
  else:
    total += (v*M)
    break
    
print(total)

from collections import defaultdict
N, M = map(int,input().rstrip().split())
d = defaultdict(lambda: 0)
for _ in range(N):
    A, B = map(int,input().rstrip().split())
    d[A] += B
ans=0
for k in sorted(d.keys()):
    if d[k]<=M:
        ans += k*d[k]
    else:
        ans += k*M
    M -= d[k]
    if M<=0:break
print(ans)

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

AB.sort()

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

import sys
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
cost=0
num=0
for i in range(N):
    if num+A[i][1]>M:
        print(cost+A[i][0]*(M-num))
        return
    else:
        cost+=A[i][0]*A[i][1]
        num+=A[i][1]
print(cost)

n,m = map(int, input().split())

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

ab.sort()

payment = 0

for i in ab:
  price = i[0]
  amount = i[1]
  if amount > m:
    amount = m
  m -= amount
  payment += amount*price
  if m == 0:
    break

print(payment) 

n,m=map(int,input().split())
a=[]
for _ in range(n):
  b=list(map(int,input().split()))
  a.append(b)
  
a.sort(key=lambda x: x[0])
ans=0
h=0

for y in a:
  d=y[0]
  e=y[1]
  if h+e>m:
    ans+=(m-h)*d
    h+=(m-h)
  else:
    h+=e
    ans+=d*e

print(ans)

N,M=list(map(int,input().split()))
AB=[list(map(int,input().split())) for _ in range(N)]
AB.sort()
ans=0
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
        M=0
print(ans)


from itertools import accumulate

N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])

sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))

num = 0
ans = 0
index_ = -1
for a, b in sAB:
    index_ += 1
    num += b
    if num >= M:
        break
    ans += a*b

if index_ == 0:
    ans += sAB[0][0]*M
else:
    ans += sAB[index_][0]*(M-cum_num[index_-1])

print(ans)


# author:  Taichicchi
# created: 12.09.2020 18:05:06

import sys

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

ls = []

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

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

ans = 0

for l in ls:
    if l[1] <= M:
        M -= l[1]
        ans += l[0] * l[1]
    else:
        ans += l[0] * M
        break


print(ans)


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

@author: liang
"""

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

for i in range(N):
    a, b = 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)

# coding: utf-8

def main():
    N, M = list(map(int, input().split()))
    D = [list(map(int, input().split())) for _ in range(N)]
    D.sort()
    ans = 0
    for a, b in D:
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += a * M
            break

    print(ans)

def __starting_point():
    main()

__starting_point()

n,m = map(int,input().split())
l = []
for _ in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
l.sort()
ans = 0
for a,b in l:
  ans += min(b,m)*a
  m = max(0,m-b)
print(ans)

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


import numpy as np
n,m = map(int, input().split())
A = np.array([list(map(int, input().split())) for _ in range(n)], dtype='int64')
ind = np.argsort(A[:,0])
A = A[ind]
num = 0
money = 0
for a,b in A:
    num += b
    if num < m:
        money += a * b
    else:
        money += a * (b - (num - m))
        break
print(money)

N, M = map(int, input().split())
store_m = [list(map(int, input().split())) for i in range(N)]
store = sorted(store_m)
buy = 0
cost = 0
for i in range(N):
    buy += store[i][1]
    if buy < M:
        cost += store[i][0] * store[i][1]
    else:
        cost += store[i][0] * (M - (buy - store[i][1]))
        print(cost)
        return

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

ab_s = sorted(ab)

res = m
temp = 0

for i in range(n):
    if res <= ab_s[i][1]:
        temp += res*ab_s[i][0]
        print(temp)
        return
    else:
        temp += ab_s[i][1]*ab_s[i][0]
        res -= ab_s[i][1]

n, m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
 
ab_sorted = sorted(ab, key=lambda x:x[0])
 
num = 0
amount_of_money = 0

for i in range(n):
    buy = min(ab_sorted[i][1], m-num)
    num += buy
    amount_of_money += ab_sorted[i][0] * buy
        
    if num >= m:
        print(amount_of_money)
        return

n,m = map(int,input().split())

l = [list(map(int,input().split())) for i in range(n)]

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

r = m
i = 0
cnt = 0
while((r-l[i][1])>0):
    r -= l[i][1]
    cnt += (l[i][0]*l[i][1])
    i += 1

cnt += (r*l[i][0])

print(cnt)

n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a = sorted(a, key=lambda x:x[0])
money = 0
drink = 0
for i in range(n):
  for j in range(a[i][1]):
    drink += 1
    money += a[i][0]
    if drink == m:
      print(money)
      return

import sys
pin=sys.stdin.readline
def main():
  N,M=map(int,pin().split())
  d=[list(map(int,pin().split())) for _ in [0]*N]
  d.sort()
  cnt=0
  ans=0
  for i in d:
    if M<=cnt+i[1]:
      ans+=i[0]*(M-cnt)
      print(ans)
      return
    cnt+=i[1]
    ans+=i[0]*i[1]
  print(ans)
  return
main()

n,m = map(int, input().split())
ab = []
for i in range(n):
    a,b = list(map(int, input().split()))
    ab.append((a,b))
ab.sort()
num = 0
money = 0
for h in range(n):
    num += ab[h][1]
    if num < m:
        money += ab[h][0]*ab[h][1]
    elif num == m:
        money += ab[h][0]*ab[h][1]
        break
    else:
        money += (ab[h][0]*ab[h][1] - (num-m)*ab[h][0])
        break
print(money)

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 = sorted(AB,key = lambda x:x[0])
cost = 0

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)


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

for i in range(N):
    drinks.append(tuple(map(int, input().split())))

drinks.sort()

cnt = 0
res = 0
for i in range(N):
    res += (min(cnt + drinks[i][1], M) - cnt) * drinks[i][0]
    cnt += drinks[i][1]

    if cnt >= M:
        break

print(res)