#include<bits/stdc++.h> using namespace std; int n,m,money; struct Node{ int p,c; }a[5001]; bool cmp(Node x,Node y){ return x.p<y.p; } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) scanf("%d%d",&a[i].p,&a[i].c); sort(a+1,a+m+1,cmp); for(int i=1;i<=m;i++){ if(n<=a[i].c){ printf("%d",money+a[i].p*n); return 0; } money+=a[i].p*a[i].c; n-=a[i].c; } } /************************************************************** Problem: 1940 User: chenshuo Language: C++ Result: Wrong Answer ****************************************************************/