n,l = map(int,raw_input().split()) arr = [map(int,raw_input().split()) for i in range(n)] wait_time = 0 for i in range(n): x, w, t = arr[i] arrive_time = x + wait_time rest = t - (arrive_time%t) signal_color = (arrive_time/t)%2 # 0..blue 1..red if signal_color == 0 : if rest < w: wait_time += rest + t else : wait_time += rest print l + wait_time