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