#include using lint = long long; void solve() { int n; lint l; std::cin >> n >> l; lint wait = 0; while (n--) { lint x, w, t; std::cin >> x >> w >> t; lint ct = (x + wait) % (t * 2); if (ct > t - w) { wait += t * 2 - ct; } } std::cout << l + wait << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }