#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>
#include<climits>
#include<chrono>
#include<iomanip>
using namespace std;
using namespace tr1;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
#define pii  pair<ll, ll>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define ff first
#define nitro_boost ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0);
#define ss second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1000000009;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
///////////////////////////////////////////////////////////////
#define curr_time std::chrono::high_resolution_clock::now()
int main(){
    nitro_boost;
	ll N,C;
	cin>>N>>C;
	vector<pii> event;
	for(ll i=0;i<N;i++){
		ll a,b,c;
		cin>>a>>b>>c;
		event.push_back({a-1,c});
		event.push_back({b,-c});
	}
	sort(event.begin(),event.end());
	ll ans=0,fee=0,t=0;
	for(auto [x,y]: event){
		if(x!=t){
			ans+=min(C,fee)*(x-t);
			t=x;
		}
		fee+=y;
	}
	cout<<ans<<"\n";
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define llrep(i,n) for(ll i=0; i<(ll)n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define kiriage(x,y) (((x)+(y)-1)/(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vp;

int main(){
	ll n,cost; cin>>n>>cost;
	vll a(n),b(n),c(n);
	rep(i,n) cin>>a[i]>>b[i]>>c[i];
	map<ll, ll>mp;
	rep(i,n){
		mp[a[i]] += c[i];
		mp[b[i]+1] -= c[i];
	}
	ll sum = 0;
	ll tmp = 0;
	ll pre = 0;
	for (auto p:mp){
		sum += min(tmp, cost) * (p.first-pre);
		tmp += p.second;
		pre = p.first;
	}
	cout << sum << endl;
}