#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <iomanip>
#include <set>
#include <bitset>
#define INT_MINs -2000000000
#define INT_MAXs 1000000001
#define MID int mid=(l+r)/2
#define REP1(i,x,y) for(int i=x;i<y;i++)
#define REP2(i,x,y) for(int i=x;i<=y;i++)
#define ls (2*k)
#define rs (2*k+1)
#define lson l,mid,2*k
#define rson mid+1,r,2*k+1
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0);
#define pb(a) push_back(a)
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1000000007;
const ll ba=131;
ll qk(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%mod;y>>=1;x=x*x%mod;}return ans;}
const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { -1,0,1,0,-1,1,-1,1};
const int dxx[8]= {2,1,-1,-2,-2,-1, 1, 2},dyy[8]= {1,2,2,1, -1,-2,-2,-1};
int a[200005],b[200005];
ll c[200005];
int d[400005];
ll num[400005];
int cnt;
void solve()
{
    int n;
    ll m;
    scanf("%d%lld",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d%d%lld",&a[i],&b[i],&c[i]);
        d[++cnt]=a[i];
        d[++cnt]=b[i]+1;
    }
    sort(d+1,d+1+cnt);
    cnt=unique(d+1,d+1+cnt)-(d+1);
    //printf("%d\n",cnt);
    for(int i=1;i<=n;i++){
        int l=lower_bound(d+1,d+1+cnt,a[i])-d;
        int r=lower_bound(d+1,d+1+cnt,b[i]+1)-d;
        num[l]+=c[i];
        num[r]-=c[i];
    }
    ll sum=0;
    for(int i=1;i<=cnt;i++){
        num[i]+=num[i-1];
        if(m<=num[i]){
            sum+=m*1ll*(d[i+1]-d[i]);
        }else{
            sum+=num[i]*1ll*(d[i+1]-d[i]);
        }
    }
    printf("%lld\n",sum);
}
int main()
{
    //IOS;
    solve();
    return 0;
}




#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i:x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l)<=(x) && (x)<(r))
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return true;} else return false;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return true;} else return false;}

int main() {
    ll N, C;
    cin >> N >> C;
    vector<pii> event;
    rep(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        event.emplace_back(a, c);
        event.emplace_back(b+1, -c);
    }
    sort(event.begin(), event.end());
    ll ans = 0, temp = 0, now = 0;
    for (auto [day, cost] : event) {
        if (day != now) {
            ans += min(C, temp) * (day - now);
            temp += cost;
            now = day;
        } else temp += cost;
    }
    cout << ans << '\n';    
    return 0;
}