N,L = map(int,input().split()) s=l=0 for i in range(N): x,w,t = map(int,input().split()) s,l = s+x-l,x+w if not (s/t%2<=1 and (s+w)/t%2<=1): s += (2*t-s%(2*t)) s += w s+= L-l print(s)