N,L = map(int,raw_input().split()) XWT = sorted([map(int,raw_input().split()) for _ in range(N)]) t = 0 X0 = 0 for X,W,T in XWT: t += X-X0 if t/T%2 == 0 and (t+W)/T-t/T > 0: t += (T-t%T)+T else: t += (T-t%T) t += W X0 = X+W else: t += L-X0 print t