#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,c;
  cin >> n >> c;
  long long a[n][3];
  for(long long i=0;i<n;++i){
    for(int j=0;j<3;++j){
      cin >> a[i][j];
    }
  }
  map<long long, long long> m;
  for(int i=0;i<n;++i){
      m[a[i][0]]+=a[i][2];
      m[a[i][1]+1]+=(-a[i][2]);
  }
  map<long long, long long>::iterator itr; 
  long long sum=0;long long val=0;
  for (itr = m.begin(); itr != m.end(); ++itr){
      itr->second+=val;
      val=itr->second;
  }
  map<long long, long long>::iterator it = m.begin();
  for (itr = m.begin(); itr != m.end()--; ++itr){
      it++;
      if(itr->second<c){
          int diff = it->first - itr->first;
          sum+=(itr->second*diff);
      }
      else{
          int diff = it->first - itr->first;
          sum+=(c*diff);
      }
  } 
  cout << sum << endl;
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
vector<int> Times;
int a[200200],b[200200];
long long c[200200];
long long delta[400400];
int main()
{
  int N;
  long long C;
  cin>>N>>C;
  for(int i=0;i<N;i++)
  {
    cin>>a[i]>>b[i]>>c[i];
    b[i]++;
    Times.push_back(a[i]);
    Times.push_back(b[i]);
  }
  sort(Times.begin(),Times.end());
  for(int i=0;i<N;i++)
  {
    a[i]=lower_bound(Times.begin(),Times.end(),a[i])-Times.begin();
    b[i]=lower_bound(Times.begin(),Times.end(),b[i])-Times.begin();
  }
  int sz=Times.size();
  for(int i=0;i<N;i++)
  {
    delta[a[i]]+=c[i];
    delta[b[i]]-=c[i];
  }
  long long tot=0;
  long long cost=0;
  for(int i=0;i<sz-1;i++)
  {
    tot+=delta[i];
    cost+=min(tot,C)*(Times[i+1]-Times[i]);
  }
  cout<<cost<<endl;
  return 0;
}