#include <bits/stdc++.h>
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define ce(e,i,n) cout<<e<<" \n"[i==(int)n-1];
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//   = 0  - [i] {} '\n'  p _  ? ^
	int n;
	long long c,x,y,z;;
	cin>>n>>c;
	vector<pair<long long,long long>>a;
	forn(i,n){
		cin>>x>>y>>z;
		a.push_back({x-1,z});
		a.push_back({y,-z});
	}
	sort(a.begin(),a.end());
	long long ans=0,b=0,to=0;
	//for(auto e:a)cout<<e.first<<" "<<e.second<<endl;
	forn(i,a.size()){
		ans+=min(c,to)*(a[i].first-b);
		b=a[i].first;
		to+=a[i].second;
	}
	cout<<ans<<'\n';
}
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   Y            imag()
#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-15);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const ll N=200000+5,mod=998244353,sh=1000000,inf=100000000;
ll a[N],b[N],c[N];
map<ll,ll> arr;
int main(){
    GO();
    int T=1;
  //  cin>>T;
    while(T--){

        int n,cc;
        cin>>n>>cc;
        for(int i=0;i<n;i++){
            cin>>a[i]>>b[i]>>c[i];
            arr[a[i]]+=c[i];
            arr[b[i]+1]-=c[i];
        }
        ll ans=0;
        auto pre=arr.begin();
        for(auto it=next(arr.begin());it!=arr.end();it++){
            ll ff=(*it).first;
            ll ss=(*it).second;

            (*it).second+=(*pre).second;
            ans+= (ff-(*pre).first)*min(cc*1ll,(*pre).second);
            pre=it;

        }
        cout<<ans<<"\n";


    }
}

















