#include #include int main(void){ int N,L; scanf("%d%d",&N,&L); int time=0; int pro=0; while(N>0){ int X,W,T; scanf("%d%d%d",&X,&W,&T); time+=X-pro; pro=X; if((time/T)%2==0 && ((time+W)/T)%2==0){ time+=W; pro+=W; } else { time+=T-(time%T)+T+W; pro+=W; } N--; } time+=L-pro; printf("%d\n",time); return 0; }