N,L=map(int,input().split()) NOW=0 TIME=0 for i in range(N): x,w,t=map(int,input().split()) TIME+=x-NOW if 0<=TIME%(t*2)<=t-w: NOW=x+w TIME+=w else: TIME+=t*2-TIME%(t*2)+w NOW=x+w TIME+=L-NOW print(TIME)