#include <bits/stdc++.h>
#define int long long
using namespace std;
int h[10005] , t , m , l[10005] , xjb[10005] , ans = 0 , n;
void f()
{
for(int i = 1; i <= m; i++)
{
xjb[i] = l[i] / h[i];
}
sort(xjb , xjb + m);
for(int i = 1; i <= m ; i++)
{
int x = i;
for(int j = 1; j <= m; j++)
{
if(xjb[i] == l[j] / h[j])
{
j = x;
continue;
}
}
}
int n = t;
for(int i = 1 ; i <= m ; i++)
{
while(n >= h[i])
{
ans += l[i];
n = n - h[i];
}
}
return ;
}
signed main()
{
cin >> t >> m;
for(int i = 1; i <= m; i++)
{
cin >> h[i] >> l[i];
}
f();
cout << ans << endl;
return 0;
}
TLE了,(算了个性价比)
放弃了,求调