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: nowt += x - nowp nowp = x if nowt % (2 * t) > t or (nowt + w) % (2 * t) > t: nowt = - (-nowt // (2 * t)) * (2 * t) nowt += L - nowp print(nowt)