import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, L = map(int, readline().split()) m = map(int, read().split()) XWT = zip(m, m, m) total_wait = 0 for x, w, t in XWT: now = total_wait + x blue = now // (t + t) * (t + t) if now + w <= blue + t: # 渡り切れる pass else: total_wait += blue + t + t - now answer = L + total_wait print(answer)