1 #include <iostream>
2 #include <algorithm>
3 using namespace std;
4 #define N 105
5
6 struct treasure_node{
7 int pi,mi;
8 };
9
10 treasure_node treasure[N];
11
12 bool cmp(treasure_node a,treasure_node b){
13 return a.pi>b.pi;
14 }
15
16 int main(){
17 //#ifndef ONLINE_JUDGE 宏定义 if not defined
18 //freopen("2111in.txt","r",stdin);
19 //#endif
20
21 int v,n,i,value;
22 while (scanf("%d",&v)!=EOF&&v){
23 scanf("%d",&n);
24 for (i=0;i<n;i++)
25 scanf("%d%d",&treasure[i].pi,&treasure[i].mi);
26 sort(treasure,treasure+n,cmp);
27 value=0;
28 for (i=0;i<n&&v;i++){
29 if (v>=treasure[i].mi){ //当背包容量大于宝贝体积
30 v-=treasure[i].mi;
31 value+=treasure[i].mi*treasure[i].pi;
32 }
33 else { //背包容量小于宝贝体积
34 value+=treasure[i].pi*v;
35 v=0;
36 }
37 }
38 printf("%d
",value);
39 }
40 return 0;
41 }