#include<iostream>#include<vector>usingnamespace std;intmain(){int N, m;
cin>>N>>m;
N /=10;//由于价格是10的整数倍,处理一下以降低空间/时间复杂度
vector<vector<int>>dp(m+1, vector<int>(N+1,0));
vector<vector<int>>price(61, vector<int>(3,0));//价格
vector<vector<int>>value(61, vector<int>(3,0));//重要度,价值 int v, p, q;for(int i =1; i <= m; i++){
cin>>v>>p>>q;
v /=10;//价格
p = v * p;//价值if(q ==0){
price[i][0]= v;
value[i][0]= p;}else{if(price[q][1]==0){
price[q][1]= v;
value[q][1]= p;}else{
price[q][2]= v;
value[q][2]= p;}}}int a, b, c, d, e, f;for(int i =1; i <= m; i++){for(int j =1; j <= N; j++){
a = price[i][0]; b = value[i][0];//没有附件
c = price[i][1]; d = value[i][1];//附件1
e = price[i][2]; f = value[i][2];//附件2
dp[i][j]= j >= a ?max(dp[i-1][j], dp[i-1][j-a]+b): dp[i-1][j];
dp[i][j]= j >= a+c ?max(dp[i][j], dp[i-1][j-a-c]+b+d): dp[i][j];
dp[i][j]= j >= a+e ?max(dp[i][j], dp[i-1][j-a-e]+b+f): dp[i][j];
dp[i][j]= j >= a+c+e ?max(dp[i][j], dp[i-1][j-a-c-e]+b+d+f): dp[i][j];}}
cout<<dp[m][N]*10;return0;}