70 3
71 100
69 1
1 2
#include <iostream>
#include <string.h>
using namespace std;
int dp[105][1005], w[105],v[105],T,M;
int max(int x,int y)
{ return x>y?x:y; }
void f( )
{ int i,j;
for (i=M; i>=1; i--)
for (j=0;j<=T; j++)
{ if (i==M+1) dp[i][j]=0;
else dp[i][j]=dp[i+1][j];
if (j>=w[i]) dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
}
}
int main()
{ int i;
cin>>T>>M;
for ( i=1; i<=M; i++) cin>>w[i]>>v[i];
f( );
cout<<dp[1][T]<<endl;
return 0;
}