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(); total += x - current; if (total % (2 * t) < t && (total + w) % (2 * t) <= t) { } else { total += 2 * t - total % (t * 2); } total += w; current = x + w; } total += l - current; System.out.println(total); } }