#如下。
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
struct mad{
float use,val,aver;
}f[N];
bool cmp(mad x,mad y)
{
return (x.aver<y.aver);
}
int main ()
{
long long t,m,i,j,dp[N];
cin>>t>>m;
for(i=1;i<=m;i++)
cin>>f[i].use>>f[i].val, f[i].aver=f[i].val/f[i].use;
sort(f+1,f+m+1,cmp);
dp[0]=0;
for(i=1;i<=t;i++)
for(j=1;j<=m;j++)
{
if(i>=f[j].use)
{
dp[i]=f[j].val+dp[i-(int)f[j].use];
}
}
cout<<dp[t];
}