n,l=map(int,input().split()) now=time=0 for _ in range(n): x,w,t=map(int,input().split()) diff=x-now now=x+w time+=diff if (time//t)%2:#着いた時点で赤信号 rem=t-time%t time+=rem+w else: rem=t-time%t if rem>=w: time+=w else: time+=rem+t+w print(time+l-now)