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