#include <bits/stdc++.h>
//#define int long long
#define endl '\n'
#define mod 998244353
using namespace std;
const int G = 1e2+5;
const int D = 1e2+5;
struct node{
int t,f,h;
}a[G];
int d,g;
int f[G][D];
inline bool cmp(node x1,node x2){
return x1.t <= x2.t;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("app.in","r",stdin);
// freopen("app.out","w",stdout);
cin >> d >> g;
int &n = g;
int &m = d;
int T,F,H;
for(int i = 1; i <= n; i++){
cin >> T >> F >> H;
a[i] = (node){T,F,H};
}
sort(a+1,a+1+n,cmp);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
f[i][j] = -1;
f[0][0] = 10;
for(int i = 0; i < n; i++){
for(int j = 0; j <= m; j++){
if(f[i][j] < a[i+1].t) continue;
f[i+1][j] = max(f[i+1][j],f[i][j]+a[i+1].f);
int to = min(j+a[i+1].h,m);
f[i+1][to] = max(f[i+1][to],f[i][j]);
}
if(f[i+1][m] >= a[i+1].t){
cout << a[i+1].t << endl;
return 0;
}
}
int ans = 10;
for(int i = 1; i <= n; i++){
if(ans >= a[i].t)
ans += a[i].f;
else break;
}
cout << ans << endl;
return 0;
}
大数据 sort 注释就不会