N,L=map(int,raw_input().split()) XWT=[map(int,raw_input().split()) for i in range(N)] ans=0 pos=0 for X,W,T in XWT: ans+=X-pos if (ans/T)%2==1: ans=(ans/T+1)*T elif ans/T!=(ans+W-1)/T: ans=(ans/T+2)*T ans+=W pos=X+W print ans+(L-pos)