#include <bits/stdc++.h>
using namespace std ;
int N , M ;
struct _cos {
int w ;
int v ;
} a[3000010];
int f[3000100] ;
int main ( )
{
f[1] = 1 ;
cin >> N >> M ;
for ( int i = 1 ; i <= M ; i ++ ) {
cin >> a[i].v ;
cin >> a[i].w ;
}
for ( int i = 1 ; i <= M ; i ++ ) {
for ( int j = N ; j >= a[i].v ; j -- ) {
f[j] = max ( f[j] , f[j - a[i].v ] + a[i].v * a[i].w ) ;
// cout << f[j] << ' ';
}
// cout << endl ;
}
cout << f[N] ;
return 0 ;
}