1 #include <bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 const int maxn = 1e4 + 10; 5 int n,k,b[maxn],dp[maxn]; 6 struct node{ 7 int p,t; 8 }a[maxn]; 9 bool cmp(node b,node c){ 10 if(b.p != c.p) 11 return b.p > c.p; 12 return b.t > c.t; 13 } 14 signed main(){ 15 //freopen("in","r",stdin); 16 ios::sync_with_stdio(0); 17 cin >> n >> k; 18 for(int i = 1; i <= k; i++) 19 cin >> a[i].p >> a[i].t,b[a[i].p]++; 20 sort(a + 1, a + 1 + k,cmp); 21 int cnt = 1; 22 for(int i = n; i >= 1; i--){ 23 if(!b[i]) 24 dp[i] = dp[i + 1] + 1; 25 else{ 26 for(int j = 1; j <= b[i]; j++){ 27 dp[i] = max(dp[i],dp[i + a[cnt++].t]); 28 } 29 } 30 } 31 cout << dp[1] << endl; 32 return 0; 33 }