import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final long L = sc.nextLong(); int[] xs = new int[N]; int[] ws = new int[N]; long[] Ts = new long[N]; for(int i = 0; i < N; i++){ final int x = sc.nextInt(); final int w = sc.nextInt(); final long T = sc.nextLong(); xs[i] = x; ws[i] = w; Ts[i] = T; } long total_time = 0; for(int i = 0; i < N; i++){ final long arrival_time = total_time + (xs[i] - (i == 0 ? 0 : (xs[i - 1] + ws[i - 1]))); final long walk_time = Math.max(0, Ts[i] - arrival_time % (2 * Ts[i])); if(walk_time >= ws[i]){ total_time = arrival_time + ws[i]; }else{ final long arrival_wait_time = (arrival_time + (2 * Ts[i] - 1)) / (2 * Ts[i]) * (2 * Ts[i]); total_time = arrival_wait_time + ws[i]; } //System.out.println(arrival_time + " " + walk_time + " " + total_time); } total_time += (L - (xs[N - 1] + ws[N - 1])); System.out.println(total_time); } }