#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=100005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;

int n,m,k[maxn],s[maxn],t[maxn];
int cur[maxn];
vector<pii> p;

bool check(int x){
    for(int i=1;i<=m;i++) cur[i]=k[i];
    priority_queue<pii,vector<pii>,greater<pii>> pq;
    int pre=0;
    for(pii d:p){
        int cnt=inf;
        if((d.fi-pre)<inf/x) cnt=(d.fi-pre)*x;
        while(cnt && !pq.empty()){
            int id=pq.top().se;
            int num=min(cur[id],cnt);
            cnt-=num;cur[id]-=num;
            if(cur[id]==0) pq.pop();
        }
        pre=d.fi;
        if(d.se<0 && cur[-d.se]!=0) return false;
        else if(d.se>0) pq.push({t[d.se],d.se});
    }
    return true;
}

void solve(){
    cin >> m >> n;
    for(int i=1;i<=m;i++){
        cin >> k[i] >> s[i] >> t[i];
        p.push_back({s[i],i});
        p.push_back({t[i]+1,-i});
    }
    sort(p.begin(),p.end());
    int l=1,r=inf,res=inf;
    while(r>=l){
        int mid=(l+r)>>1;
        if(check(mid)) res=mid,r=mid-1;
        else l=mid+1;
    }
    cout << res << '\n';
}

signed main(){
    freopen("schedule.inp","r",stdin);
    freopen("schedule.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
