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