#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<60; const ll MOD = 1000000007; const double EPS = 1e-10; ll n, l; ll x[100], w[100], t[100]; int main() { cin >> n >> l; REP(i, n) scanf("%lld %lld %lld", x + i, w + i, t + i); ll ans = 0, pos = 0; REP(i, n) { ans += x[i] - pos; if (ans % (2 * t[i]) >= t[i]) ans += 2 * t[i] - ans % (2 * t[i]); if (t[i] - (ans % t[i]) < w[i]) ans += 2 * t[i] - (ans % t[i]); ans += w[i]; pos = x[i] + w[i]; } ans += l - (x[n - 1] + w[n - 1]); cout << ans << endl; return 0; }