def read_data(): N, L = map(int, input().split()) xwt = [] for i in range(N): x, w, t = map(int, input().split()) xwt.append((x, w, t)) return N, L, xwt def solve(N, L, xwt): time = 0 pos = 0 for x, w, t in xwt: time += x - pos red_start = (time // t) % 2 red_goal = ((time + w - 1) // t) % 2 # 赤信号に切り替わると同時に渡りきるのでもOK。渡り終える1秒前に青かどうかをチェックする。 if red_start or red_goal: time = ((time // (2 * t)) + 1) * (2 * t) time += w pos = x + w time += L - pos return time N, L, xwt = read_data() print(solve(N, L, xwt))