# -*- coding: utf-8 -*- n, l = map(int, input().split()) x = [0] * n w = [0] * n t = [0] * n for i in range(n) : x[i], w[i], t[i] = map(int,input().split()) time = 0 place = 0 i = 0 while place < l : if i >= n: place += 1 time += 1 else: if place == x[i]: if time % (2 * t[i]) < t[i] and (time + w[i]) % (2 * t[i]) <= t[i]: place += w[i] time += w[i] else : time += 2 * t[i] - (time % (2 * t[i])) + w[i] place += w[i] i += 1 elif place != x[i] and place != l-1: place += 1 time += 1 print(time)