n, l = map(int, input().split()) c = 0 ans = 0 for _ in range(n): x, w, t = map(int, input().split()) ans += x - c q, r = divmod(ans, t) if q % 2 == 0: if r + w <= t: ans += w else: ans += w + t + (t - r) else: ans += t - r + w c = x + w ans += l - c print(ans)