#include typedef struct{ int x; int w; int t; }JUNCTION; JUNCTION junc[105]; int main(void){ int i; int N,L; int time = 0; scanf("%d %d", &N, &L); junc[0].x = 0; junc[0].w = 0; junc[0].t = 0; for(i=1;i<=N;i++){ scanf("%d %d %d", &junc[i].x, &junc[i].w, &junc[i].t); } junc[N+1].x = L; junc[N+1].w = 0; junc[N+1].t = 0; for(i=1;i<=N+1;i++){ int nowSignal; int dis = junc[i].x - junc[i-1].x; time += dis; if(junc[i].x == L){ break; } nowSignal = time%(junc[i].t*2); if( nowSignal < junc[i].t ){ if( junc[i].t < (nowSignal+ junc[i].w)){ time += junc[i].t-nowSignal; time += junc[i].t; } }else{ time += (junc[i].t*2) - nowSignal; } } printf("%d\n", time); return 0; }