#include<iostream> using namespace std; const int N = 1010; int f[N]; int n, m; int main(){ while(cin >> m >> n){ for(int i = 0, v, w; i < n; i ++ ){ cin >> v >> w; for(int j = m; j >= v; j -- ) f[j] = max(f[j],...