n,L = map(int,input().split()) T = v = 0 for _ in range(n): x,w,t = map(int,input().split()) T += x-v if T%(2*t) > t-w: T = (T//(2*t)+1)*2*t v = x print(T+L-v)