#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep2(i, j, n) for(int i=j;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

map<int, ll> table;
int main(){
    int N;
    cin >> N;
    ll C;
    cin >> C;
    rep(i, N){
        int a, b, e;
        cin >> a >> b >> e;
        table[a-1] += e;
        table[b] -= e;
    }
    vector<pair<int, ll>> table2;
    for(pair<int, ll> p : table){
        table2.pb(p);
    }
    sort(all(table2));
    ll rui[table2.size()+1];
    ll sum = 0;
    rui[0] = 0;
    rep(i, table2.size()){
        rui[i+1] = rui[i] + table2[i].second;
        if(i>0 && rui[i]>C){
            sum += (table2[i].first - table2[i-1].first)*C;
        } else if(i>0) {
            sum += (table2[i].first - table2[i-1].first)*rui[i];
        }
    }
   
    cout << sum << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define lx x<<1
#define rx x<<1|1
map<int,ll>mp;
int main(){
	int n,C;
	scanf("%d%d",&n,&C);
	for(int i=1;i<=n;i++){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);
		mp[a]+=c,mp[b+1]-=c;
	}
	int l=0;ll ans=0,s=0;
	for(auto p:mp){
		ans+=1LL*min(1LL*C,s)*(p.fi-l);
		l=p.fi;
		s+=p.se;
	}printf("%lld\n",ans); 
	return 0;
}