from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): n,l=MI() xwt=[LI() for _ in range(n)] time=0 pos=0 for x,w,t in xwt: time+=x-pos if time//t%2 or (time+w)//t%2: time=(time//t+1)*t if time//t%2:time+=t time += w pos=x+w time+=l-pos print(time) main()