#!/usr/bin/python # -*- coding: utf-8 -*- N, L = map(int, raw_input().split()) time, location = 0, 0 for loop in xrange(N): X, W, T = map(int, raw_input().split()) # 信号まで歩く time += X - location location = X # 始点と終点で青ならわたっておk if 0 <= time % (2*T) < T and 0 <= (time+W-1) % (2*T) < T: time += W location += W # 行けなかったら次の青まで待つ else: nextgreen = (time/(2*T) + 1) * (2*T) time += nextgreen - time time += W location += W time += (L - location) # 君の家に着くまでずっと走ってゆく print time