import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N,L = MI() XWT = [(0,0,0)]+[tuple(MI()) for _ in range(N)] cur = 0 for i in range(N): X0,W0,T0 = XWT[i] X,W,T = XWT[i+1] cur += X-(X0+W0) t = cur % (2*T) if t+W <= T: cur += W else: cur += (2*T-t)+W X0,W0,T0 = XWT[-1] print(cur+L-(X0+W0))