N,L=map(int,input().split()) X=[list(map(int,input().split())) for _ in range(N)] iti=0 X.append((L,0,10**10)) time=0 for v,w,z in X: time+=v-iti even=time//z if not even%2: if time%z+w<=z: t=True else: time+=z+(z-(time%z)) else: time+=z-(time%z) iti=v print(time)