/* ID: zhangzz4 PROG: milk LANG: C++ */ #include<stdio.h> #include<string.h> #include<stdlib.h> struct Node { int p,a; }d[5001]; int cmp(const void *a,const void *b) { return ((Node *)a)->p - ((Node *)b)->p; } int main() { freopen("milk.in","r",stdin); freopen("milk.out","w",stdout); int n,m; scanf("%d%d",&n,&m); for(int i=0;i<m;i++) scanf("%d%d",&d[i].p,&d[i].a); qsort(d,m,sizeof(d[0]),cmp); int ans=0; for(int i=0;i<m;i++) { if(d[i].a<n) { n-=d[i].a; ans+=d[i].a*d[i].p; } else { ans+=n*d[i].p; break; } } printf("%d/n",ans); //scanf("%'d"); }