#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define DEC(x) fixed<<setprecision(x)
#define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);
const long long INF=2e18;

template<typename T,typename T1>void amax(T &a,T1 b){if(b>a)a=b;}
template<typename T,typename T1>void amin(T &a,T1 b){if(b<a)a=b;}

ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

// #define _NCR_

int TLE_TERROR()
{
 	ll n,c,l,r,k,j,z,zz,ans=0;
 	cin>>n>>c;
 	map<ll,ll>m;
 	for(ll i=0;i<n;i++)
 	{
 		cin>>l>>r>>k;
 		m[l]+=k;
 		m[r+1]-=k;
 	}
 	for(auto it=m.begin();it!=m.end();it++)
 	{
 		if(it==m.begin())
 		{
 			z=it->S;
 			continue;
 		}
 		it->S+=z;
 		z=it->S;
 	}
 	// for(auto it=m.begin();it!=m.end();it++)
 	// {
 	// 	cout<<it->F<<" "<<it->S<<endl;
 	// }
 	for(auto it=m.begin();it!=m.end();it++)
 	{
 		if(it==m.begin())
 		{
 			z=it->F;
 			zz=it->S;
 			if(zz<c)
 				ans+=zz;
 			else
 				ans+=c;
 			continue;
 		}
 		// cout<<ans<<endl;
 		ll y=it->F-z;
 		y--;
 		if(zz<c)
 			ans+=y*(zz);
 		else
 			ans+=y*c;
 		if(it->S<c)
 			ans+=it->S;
 		else
 			ans+=c;
 		z=it->F;
 		zz=it->S;
 	}
 	cout<<ans<<endl;

 	
 	return 0;   
}

int main()
{
    FAST
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll int TESTS=1;
    // cin>>TESTS;
    #ifdef _NCR_
        initialvalues();
    #endif
    while(TESTS--)
        TLE_TERROR();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    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);
    }
    sort(ALL(event));
    int ans = 0, fee = 0, t = 0;
    for (auto [x, y] : event) {
        if (x != t) {
            ans += min(C, fee) * (x - t);
            t = x;
        }
        fee += y;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}
