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; } int time = 0; int pos = 0; for(int i = 0; i < N; i++){ final int arrival_time = time + (xs[i] - pos); final int throught_time = arrival_time + ws[i]; if(arrival_time % (2 * Ts[i]) >= Ts[i]){ final int arrival_wait_time = (int) ((arrival_time + (2 * Ts[i]) - 1) / (2 * Ts[i]) * (2 * Ts[i])); time = arrival_wait_time + ws[i]; }else if(throught_time % (2 * Ts[i]) >= Ts[i]){ //System.out.println(throught_time); final int arrival_wait_time = (int) ((arrival_time + (2 * Ts[i]) - 1) / (2 * Ts[i]) * (2 * Ts[i])); //System.out.println(arrival_wait_time); time = arrival_wait_time + ws[i]; }else{ time = throught_time; } pos = xs[i] + ws[i]; } time += L - (xs[N - 1] + ws[N - 1]); System.out.println(time); } }