P1208 [USACO1.3] 混合牛奶 Mixing Milk - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
n, m = map(int,input().split())
data = []
for i in range(m):
data.append(list(map(int,input().split())))
data.sort(key=lambda x:x[0])
i = 0
price = 0
while n>0:
if n>=data[i][1]:
n -= data[i][1]
price += (data[i][0]*data[i][1])
else:
price += n*data[i][0]
n = 0
i += 1
print(price)