#include <bits/stdc++.h>
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

*/

#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int  long long
#define mod  1000000007 //998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define double long double
#define all(o) o.begin(),o.end()



/*
#define T pair<int, int>
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
*/


using namespace std;



int power(int x, int y)
{
    int res = 1LL;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int  n)
{
    return power(n,mod-2)%mod;
}
int isprime(int n){
    if(n<2)return 0;
    int i;
    for(i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;
}
void files(){  
    // For getting input from input.txt file 
    freopen("input.txt", "r", stdin);   
    // Printing the Output to output.txt file 
    freopen("output.txt", "w", stdout); 

}

const int N=2e5+10;


int n,C;
int c[200005];
void solve(){

    map<int,int> mp;

    cin>>n>>C;

    int l,r,i;
    vector<pii> v;
    for(i=1;i<=n;i++){
        cin>>l>>r>>c[i];
        v.pb({l,i});
        v.pb({r+1,i});
    }

    sort(all(v));
    int ans=0;
    int cost=0;
    for(i=0;i<v.size();i++){

        int cur=v[i].fi,id=v[i].si;
        
        int d=0;
        if(i)
            d=cur-v[i-1].fi;
      
        ans+=min(cost,C)*d;

        mp[id]++;
        if(mp[id]==1)
            cost+=c[id];
        else
            cost-=c[id];
    }
    cout<<ans<<"\n";



} 


int32_t main(){ 
     fast

    int t=1;



      // cin>>t;
    
    while(t--) 
    {
        solve();
    }
}
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, C; cin >> N >> C;
  map<int, ll> um;
  F0R(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    um[a] += c;
    um[b + 1] -= c;
  }
  int day = 0;
  ll cs = 0, r = 0;
  for (auto [a, c] : um) {
    //cout << a << ',' << c << newl;
    r += (ll)(a - day) * min<ll>(cs, C);
    cs += c;
    day = a;
  }
  cout << r;
}
#endif
