N, L = map(int, input().split()) ans, pre = 0, 0 for i in range(N): X, W, T = map(int, input().split()) now = (ans + X - pre) % (2 * T) if T - now < W: ans += 2 * T - now ans += X + W - pre pre = X + W ans += L - pre print(ans)