//بسم الله الرحمن الرحيم

// ----->  Author :    N A Y E M
// ----->           [ CSE-19 , CU ]

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
typedef unsigned long long ull ;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
//using u128 = __uint128_t;
#define el << '\n'
#define sz(v) ((int)(v).size())
#define PI 3.141592653589793238
#define _test_ int _ ; cin >> _ ; while( _-- )
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ) ; }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ) ; }
ll big_mod(ll base , ll power , ll mod){
    ll ret=1;base%=mod;while(power){if(power&1)ret=ret*base%mod;base=base*base%mod;power>>=1;}return ret;}
ll mod_inverse(ll a , ll mod ){ return big_mod(a,mod-2,mod);}
ull POW(ll a , ll b){if(b==0) return 1;ull ret=1;while(b--)ret*=a;return ret;}
int dx[]={0,0,+1,-1,+1,-1,-1,+1} ;
int dy[]={+1,-1,0,0,+1,-1,+1,-1} ;
// ------------------>
const ll infLL = 1e15;
const int inf = 1e9;
const ll mod = 1e9+7;
const ll mX = 3e5+123;
// ------------------>
ll N,C,sum,total;

void _case_()
{
    cin >> N >> C ;
    vll v;
    for(int i=0;i<N;i++)
    {
        ll a,b,c;
        cin >> a >> b >> c;
        sum+=(b-a+1)*c;
        v.push_back({a,c});
        v.push_back({b+1,-c});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<2*N;i++)
    {
        total += v[i].second ;
        if(total>C)
            sum -= (total-C)*(v[i+1].first-v[i].first);
    }
    cout << sum el;
}

int main( )
{
    optimize() ;
    //_test_
        _case_() ;
    return 0 ;
}
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a / gcd(a, b) * b;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template <class T>
void CVEC(const T &v) {
	int c = v.size() - 1;
	for (int i = 0; i < c; i++) cout << v[i] << ' ';
	if (c > -1) cout << v[c];
	cout << '\n';
}

#pragma endregion header

signed main(){
    int N, C; cin >> N >> C;
	vector<pair<int, int>> ma;
	rep(i,N) {
		int a, b, c; cin >> a >> b >> c;
		a--;
		ma.emplace_back(a, c);
		ma.emplace_back(b, -c);
	}
	sort(ALL(ma));
	int ans = 0;
	int now = 0;
	int today = 0;
	for(auto [x, y] : ma){
		if(x != today){
			ans += min(C, now) * (x - today);
			today = x;
		}
		now += y;
	}
	cout << ans << endl;
}