n, l = gets.split.map(&:to_i) time = 0 bx = 0 n.times do x, w, t = gets.split.map(&:to_i) diff = x - bx time += diff mt = time % (t * 2) if mt < t && mt + w <= t time += w else time += t * 2 - mt + w end bx = x + w end puts time + l - bx