#include using namespace std; int main() { int N, L; cin >> N >> L; int wait = 0; for (int i = 0; i < N; i++) { int x, w, t; cin >> x >> w >> t; int cur = x + wait; int s = cur % (2 * t), e = s + w; if (e > t) wait += 2 * t - s; } cout << wait + L << endl; }