N, L = map(int, input().split()) XWT = [list(map(int, input().split())) for _ in range(N)] nowt = 0 nowp = 0 for x, w, t in XWT: t2 = t * 2 nowt += x - nowp nowp = x if nowt % t2 <= t and (nowt + w) % t2 <= t and nowt // t2 == (nowt + w) // t2: continue else: nowt = - (-nowt // (2 * t)) * (2 * t) nowt += L - nowp print(nowt)