n,l = map(int, raw_input().split()) ls = [map(int, raw_input().split()) for _ in range(n)] time = 0 pos = 0 for [x,w,t] in ls: reach = time + (x-pos) cycle = reach / (2*t) if cycle * 2 * t <= x and x+w <= cycle * 2 * t + t: time = reach + w else: wait = (cycle+1)*2*t - reach time = reach + wait + w pos = x + w time += l - pos print time