#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
const ll INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

int main()
{
    ll n, C;
    cin >> n >> C;

    // time, cost
    map<ll, ll> mp;
    for (ll i = 0; i < n; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        mp[a] += c;
        mp[b + 1] -= c;
    }
    mp[0] = 0;

    ll nowCost = 0;
    ll prevTime = 0;
    ll ans = 0;
    for (auto m : mp)
    {
        ll time = m.first;
        ll cost = m.second;
        ans += min(C, nowCost) * (time - prevTime);
        nowCost += cost;
        prevTime = time;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vi  = vector<int>;
using ull = unsigned long long;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod  = 1e9+7;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e6+10;
int main() {
#ifndef WA_DEBUG
    ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
    int n;
    ll c;
    cin>>n>>c;
    vector<pair<int,int>> a(2*n+1);
    int cnt=0;
    rep(i,1,n) {
        int l,r,c;
        cin>>l>>r>>c;
        a[++cnt].fi=l;
        a[cnt].se=c;
        a[++cnt].fi=r+1;
        a[cnt].se=-c;
    }
    sort(a.begin()+1,a.end());
    ll sum=0,now=0;
    rep(i,1,cnt-1) {
        now+=a[i].se;
        if(now<c) sum+=now*(a[i+1].fi-a[i].fi);
        else sum+=c*(a[i+1].fi-a[i].fi);
    }
    cout<<sum<<'\n';
    return 0;
}
