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

using ll=long long;

int main(){
    ll N,C;
    cin >> N >> C;
    map<int,ll> P;
    for(int i=0;i<N;i++){
        int A,B,C;
        cin >> A >> B >> C;
        P[A]+=C;
        P[B+1]-=C;
    }
    ll S=0;
    ll ans=0;
    ll prev=0;
    for(auto it=P.begin();it!=P.end();it++){
        ll A=(*it).first;
        ll B=(*it).second;
        ans+=min(C,S)*(A-prev);
        prev=A;
        S+=B;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 
 
//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;
 
using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void init()
{

}

void solve()
{
    int n;
    cin>>n;
    ll c;
    cin>>c;
    map<int, ll> mm1, mm2;
    vi v1, v2;
    vector<pair<ll, ll>> v;
    // vecot v1;
    rep(i,n)
    {
        int x, y, z;
        cin>>x>>y>>z;
        if(mm1[x]==0)
            v1.pb(x);
        mm1[x]+=z;
        if(mm1[y+1]==0)
            v1.pb(y+1);
        mm1[y+1]-=z;
    }
    trav(x,v1)
    {
        v.pb(mp(x,mm1[x]));
    }
    sort(all(v));
    ll cost = v[0].se;
    ll ans = 0;
    repu(i,1,v.size()-1)
    {
        ans += (v[i].fi-v[i-1].fi)*min(cost,c);
        cost += v[i].se;
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;    
    init();
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}