// author : redwackyferret
#include<bits/stdc++.h>
#define pb push_back
#define pdd pair<ld, ld>
#define int long long
#define ff first
#define pii pair<int,int>
#define ss second
#define pp make_pair
#define endl "\n"
#define ll long long
#define ld long double
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define PI 3.1415926535 
#define mst(v, x) memset(v, x, sizeof v);
#define all(v) v.begin(), v.end()

// __builtin_clz(x) returns num of zeroes at beginning of bit representation
// __builtin_ctz(x) num of zeroes at end of bit representation
// __builtin_popcount(x) num of ones
// __bultin_parity(x) parity of num of ones in bit representation

using namespace std;

void IOS(){ios::sync_with_stdio(false); cout.precision(10); cout << fixed;}
const int MOD = 1e9 + 7;
#define INF 2000000000
const int mx = 1e5+5;

int i, j, k;

ll gcd(ll x, ll y)
{      if (y == 0)return x;
       return gcd(y, x % y); 
}

ll lcm(ll x, ll y){
       return (x*y)/gcd(x,y);
}

struct st{
	int a, b, c;
};

int32_t main(){
	IOS();
	int n,C;
	cin>>n>>C;
	vector<pair<int,int>>event;
	REP(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		event.emplace_back(a-1,c);
		event.emplace_back(b,-c);
	}
	
	int ans = 0;
	sort(all(event));
	int fee = 0, t=0;
	for(auto z : event){
		int x = z.ff, y = z.ss;
		if(x!=t){
			ans += min(C, fee)*(x-t);
			t=x;
		}
		fee+=y;
	}
	cout<<ans<<endl;
	
return 0;
}

#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

// べき乗の剰余（a^b mod MOD）
ll bpow(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j;

    ll N, C;
    cin >> N >> C;
    vll va, vb, vc;
    for(i = 0; i < N; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        va.push_back(a);
        vb.push_back(b);
        vc.push_back(c);
    }
    vector<pll> P;
    for(i = 0; i < N; i++) {
        P.push_back(pll(va[i], vc[i]));
        P.push_back(pll(vb[i] + 1, -1 * vc[i]));
    }
    sort(P.begin(), P.end());

    ll ans = 0;
    ll tc = 0;
    ll now = P[0].first;
    ll pi = 0;
    while(1) {
        while(P[pi].first == now) {
            tc += P[pi].second;
            pi++;
            if(pi >= 2 * N)
                break;
        }
        if(pi >= 2 * N)
            break;
        ll ttc;
        if(tc > C) {
            ttc = C;
        } else {
            ttc = tc;
        }
        ans += ttc * (P[pi].first - now);
        now = P[pi].first;
    }
    cout << ans << endl;

    return 0;
}
