import java.util.Scanner; public class Main_yukicoder139 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int l = sc.nextInt(); int[] x = new int[n + 1]; int[] w = new int[n + 1]; int[] t = new int[n + 1]; for (int i = 0; i < n; i++) { x[i + 1] = sc.nextInt(); w[i + 1] = sc.nextInt(); t[i + 1] = sc.nextInt(); } long time = 0; for (int i = 1; i <= n; i++) { time += x[i] - (x[i - 1] + w[i - 1]); if (time / t[i] % 2 == 1) { time += t[i] - time % t[i]; } else if ((time + w[i]) / t[i] % 2 == 1 && (time + w[i]) % t[i] != 0) { time += t[i] - time % t[i] + t[i]; } time += w[i]; } System.out.println(time + l - (x[n] + w[n])); sc.close(); } }