package no139; import java.util.Scanner; public class Main { 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+2]; int[] w = new int[n+2]; int[] t = new int[n+2]; x[0] = 0; w[0] = 0; t[0] = 10; for(int i=1;i<=n;i++) { x[i] = sc.nextInt(); w[i] = sc.nextInt(); t[i] = sc.nextInt(); } x[n+1] = l; long time = 0; for(int i=0;i<=n;i++) { long gap = x[i+1] - x[i]; long ph0 = time % (t[i] * 2); long ph1 = (time + w[i]) % (t[i] * 2); if (ph0 <= ph1 && ph1 <= t[i]) { time += gap; }else{ time += t[i] * 2 - ph0 + gap; } } System.out.println(time); } }