N, L = gets.split.map(&:to_i) X, W, T = (1..N).map {gets.split.map(&:to_i)}.transpose s, p = X.zip(W, T).inject([0, 0]) {|(s, p), (x, w, t)| y = s + x - p if t - (y % (2 * t)) <= w [y + (2 * t - (y % (2 * t))) + w, x + w] else [y + w, x + w] end } ans = s + L - p puts ans