#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
vector<int>val;
int l[200005],r[200005],cst[200005];
int n,c;
int use[400005],un[400005],st[400005],tot[400005];
int ans;
void input(){
	cin>>n>>c;
	rep(i,n){
		cin>>l[i]>>r[i]>>cst[i];
		val.pb(l[i]),val.pb(r[i]+1);
	}
    sort(all(val));
    val.erase(unique(all(val)),val.end());
    rep(i,n){
    	l[i]=lower_bound(all(val),l[i])-val.begin();
    	r[i]=lower_bound(all(val),r[i]+1)-val.begin();
    	st[l[i]]+=cst[i];
    	st[r[i]]-=cst[i];
	}
	int k=st[0];
	rept(i,1,sz(val)){
		int n_cst=min(c,k)*(val[i]-val[i-1]);
		k+=st[i];
		ans+=n_cst;
	}
	cout<<ans;
}
signed main()
{
	input();
	re 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define endl "\n"

void solve(){
    ll n,c;
    cin>>n>>c;
    vector<pair<ll,ll>> arr;
    for(ll i=0;i<n;i++){
        ll a,b,k;
        cin>>a>>b>>k;
        arr.push_back({a,k});
        arr.push_back({b+1,-k});
    }
    sort(arr.begin(),arr.end());
    ll ans=0,sum=0,t=0;
    for(auto [x,y]:arr){
        if(x!=t){
            ans += min(c,sum)*(x-t);
            t=x;
        }
        sum+=y;
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll tc=1;
    // cin>>tc;
    for(ll t=1;t<=tc;t++){
        // cout<<"Case #"<<t<<": ";
        solve();
    }
}