#include using namespace std; int main(){ int n,l; cin>>n>>l; int now=0,time=0; int x,w,t; for(int i=0;i>x>>w>>t; time+=(x-now); now=x; if(now!=0){ if((time/t)%2==1||((time+w)/t)%2==1){ time=((time/t)+1)*t; if((time/t)%2==1) time+=t; } } time+=w; now+=w; } time+=(l-now); cout<