#include using namespace std; int main(){ long long n,l;cin>>n>>l; long long prev = 0; long long nw = 0; for(int i = 0; n > i; i++){ long long x,w,t;cin>>x>>w>>t; nw += x-prev; if(t-w < nw%(2*t))nw += 2*t-(nw%(2*t)); nw += w; prev = x+w; } cout << nw+l-prev << endl; }