#include <bits/stdc++.h>
using namespace std;
struct Station {
long long x, a, b;
bool operator<(const Station& other) const {
return x < other.x;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
long long d;
if (!(cin >> n >> d)) return 0;
vector<Station> stations(n);
for (int i = 0; i < n; ++i) {
cin >> stations[i].x >> stations[i].a >> stations[i].b;
}
sort(stations.begin(), stations.end());
long long min_f = 0;
long long current_fuel_added = 0;
for (int i = 0; i < n; ++i) {
long long deficit = stations[i].x - current_fuel_added;
if (deficit > min_f) {
min_f = deficit;
}
current_fuel_added += stations[i].a;
}
long long final_deficit = d - current_fuel_added;
if (final_deficit > min_f) {
min_f = final_deficit;
}
cout << min_f << "\n";
return 0;
}