#include<bits/stdc++.h>```c
using namespace std;
int t,m,h[200],l[200],dp[200][1100];
int main()
{
cin>>t>>m;
for(int i=1;i<=m;i++) cin>>h[i]>>l[i];
for(int i=1;i<=m;i++)
{
for(int j=t;j>=0;j--)
{
if(j>=h[i])
{
dp[i][j]=max(dp[i-1][j],dp[i-1][j-h[i]]+l[i]);
}
}
}
cout<<dp[m][t];
return 0;
}