import sys input=lambda: sys.stdin.readline().rstrip() n,l=map(int,input().split()) ans=0 cur=0 for _ in range(n): x,w,t=map(int,input().split()) ans+=x-cur cur=x if (ans//t)%2==0 and ((ans+w-1)//t)%2==0: continue else: ans=((ans-1)//t//2+1)*2*t print(ans+l-cur)