# include <bits/stdc++.h> using namespace std ; int tme [10001] , vle [10001] , dp [10001] [10001] ; int main ( ) { int t , m ; cin >> t >> m for ( int i = 1 ; i <= m ; i ++ ) { cin >> tme [i] >> vle [i] ; } for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= t ; j ++ ) { f [i] [j] = f [i - 1] [j] ; if ( ( j >= a [i] ) && ( f [i] [j] < f [i - 1] [j - a [i]] + b [i] ) ) { f [i] [j] = f [i - 1] [j - a [i]] + b [i] ; } } } cout << f [m] [t] << endl ; return 0 ; }