#include<bits/stdc++.h> 
using namespace std;

#define ll long long int
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007 
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} 
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll invMod(ll num){
  return fast_expo(num, MOD - 2)%MOD;
}

int main(){
  fast
  #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
  #endif
  
  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n, cost; cin >> n >> cost;
    vector<pair<pair<ll, ll>, ll>> arr(n);
    vector<ll> c(n);

    for(ll i = 0; i < n; ++i){
      cin >> arr[i].ff.ff >> arr[i].ff.ss >> arr[i].ss;
    }

    sort(arr.begin(), arr.end());
    ll tot = 0, curr = 0, last = 0;
    set<pair<pair<ll, ll>, ll>> S;
    vector<pair<pair<ll, ll>, ll>> vect;
    for(ll i = 0; i < n; ++i){
      vect.clear();
      for(auto j: S){
        if(j.ff.ff < arr[i].ff.ff){
          tot += (j.ff.ff - last + 1)*(min(cost, curr));
          curr -= j.ff.ss;
          last = j.ff.ff + 1;
          vect.pb({j});
        } else break;
      }

      for(auto j: vect)
        S.erase(j);

      tot += (arr[i].ff.ff - last)*(min(cost, curr));

      last = arr[i].ff.ff;
      S.insert({{arr[i].ff.ss, arr[i].ss}, i});
      curr += arr[i].ss;
    }

    for(auto j: S){
      tot += (j.ff.ff - last + 1)*(min(cost, curr));
      curr -= j.ff.ss;
      last = j.ff.ff + 1;
    }

    cout << tot << endl;
  } 
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define gc() getchar()
#define pc(a) putchar(a)
#define int long long
inline int read()
{
	int x=0,f=1;
	char c=gc();
	while(c>'9'||c<'0') 
	{
		if(c=='-') f=-f;
		c=gc();
	}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
	return x*f;
}
int nnu[25];
inline void write(long long x)
{
	if(x==0)
	{
		pc('0');
		return;
	}
	if(x<0) pc('-'),x=-x;
	int tp=0;
	while(x) nnu[++tp]=x%10,x/=10;
	while(tp) pc(nnu[tp--]+'0');
	return;
}
#define ma 5000005
int L[ma],R[ma],c[ma];
unordered_map<int,int> mp;
int book[ma],cnt;
inline void ins(int x)
{
	if(!mp[x]) book[++cnt]=x,mp[x]=1;
	return;
}
inline bool cmp(int x,int y) 
{
	return x<y;
}
inline int find(int x)
{
	int l=1,r=cnt;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(book[mid]>=x) r=mid;
		else l=mid+1;
	}
	return l;
}
int su[ma];
signed main()
{
	int n=read(),C=read();
	for(int i=1;i<=n;i++) L[i]=read(),R[i]=read(),c[i]=read(),ins(L[i]),ins(R[i]+1);
	sort(book+1,book+cnt+1,cmp);
//	for(int i=1;i<=n;i++) L[i]=find(L[i]),R[i]=find(R[i]);
	for(int i=1;i<=n;i++) su[find(L[i])]+=c[i],su[find(R[i]+1)]-=c[i];
	int ans=0;
	for(int i=1;i<=cnt;i++) su[i]+=su[i-1];
//	for(int i=1;i<=cnt;i++) if(su[i]>C) cout<<"okok\n";
//	for(int i=1;i<=cnt;i++) cout<<su[i]<<' ';
//	cout<<endl;
//	book[0]=
	for(int i=1;i<cnt;i++) ans+=min(su[i],C)*(book[i+1]-book[i]);
//	for(int i=1;i<=cnt;i++) cout<<book[i]<<' ';
//	cout<<endl;
	write(ans);
}
















