from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,L = map(int,input().split()) XWT = [tuple(map(int,input().split())) for _ in range(N)] now = 0 time = 0 for x,w,T in XWT: time += x-now now = x if time//T%2==0: if (time+w-1)//T==time//T: now = x+w time += w else: now = x+w time = w + T*(time//T + 2) else: now = x+w time = w + T*(time//T + 1) print(time + L - now)