#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define pll pair<ll,ll>
#define vll vector<long long>
#define f first
#define s second
long long mod = 1e9+7;

int diry[] = {-1,0,0,1,1,-1,-1,1};
int dirx[] = {0,-1,1,0,1,-1,1,-1};

bool comp(const pii &a,const pii &b){
    return a.second<b.second;
}

ll pow(ll x, ll y, ll p) {
    ll res = 1;
    x %= p;
    if(x == 0) {
        return 0;
    }
    while(y > 0) {
        if(y & 1) {
            res = (res * x) % p;
        }
        y >>= 1;
        x = (x * x) % p;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ull t=1,k;      
    // cin>>t;
    // cin>>k; 
  // int ulti=1;    
    while(t--){    
        ll n,c; cin>>n>>c;
        vector<pll> arr;
        for(int i=0;i<n;i++){
            ll a,b,d; cin>>a>>b>>d;
            arr.push_back({a-1,d});
            arr.push_back({b,-d});
        }
        sort(arr.begin(),arr.end());
        ll ans=0,fee=0,t=0;
        for(auto j:arr){
            ll x=j.first,y=j.second;
            if(t!=x){
                ans += min(c,fee)*(x-t);
                t = x;
            }
            fee+=y;
        }
        cout<<ans;
		cout<<endl;
    }
}
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, C; cin >> n >> C;
    ll a[n], b[n], c[n];
    rep(i, n){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }

    map<ll, ll> mp;
    rep(i, n){
        mp[a[i]] += c[i];
        mp[b[i] + 1] -= c[i];
    }

    vector<pair<ll, ll>> vec;
    for(const auto& [k, v] : mp){
        vec.push_back({k, v});
    }

    vector<pair<ll, ll>> vec2;
    ll len_vec = vec.size();
    ll cost = vec[0].second;
    rep(i, len_vec - 1){
        ll d = vec[i + 1].first - vec[i].first;
        vec2.push_back({d, cost});

        cost += vec[i + 1].second;
    }

    ll ans = 0;
    for(auto p : vec2){
        if(p.second < C){
            ans += p.first * p.second;
        }
        else{
            ans += p.first * C;
        }
    }

    cout << ans << endl;

    return 0;
}