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