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 <= reach and reach+w <= cycle * 2 * t + t: time = reach + w else: time = (cycle+1)*2*t + w pos = x + w time += l - pos print time