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(); long total = 0; int cur = 0; for (int i = 0; i < n; i++) { int point = sc.nextInt(); int width = sc.nextInt(); int time = sc.nextInt(); long start = total + point - cur; long end = total + point + width - cur; if (start / time % 2 == 1 || end / time % 2 == 1 || start / time != end / time) { cur = point; total = (start / (time * 2) + 1) * time * 2; } else { cur = point + width; total = end; } } total += l - cur; System.out.println(total); } }