#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <cmath>


using namespace std;

int main() { 
long long int n,x;
cin>>n>>x;
map<long long int,long long int> m;
//int ans=0;

int q=0;
long long int max=0;
for (int i = 0; i < n; i++)
{
    int a,b,c;
  cin>>a>>b>>c;
 m[a]+=c;
  m[b+1]-=c;
if (b>max)
{
    max=b;
}

}

for (auto p : m) {
  auto key = p.first;
  auto value = p.second;
 //cout<<key<<value<<endl;
}

long long int mon=0;
long long int ans=0;
bool big=false;
long long int before=0;
for (auto p : m)
{

if (p.first<=max)
{   
  if (mon>x)
{
   ans+=(p.first-before)*x;
}
else
{
    ans+=(p.first-before)*mon;
}
before=p.first;
 mon+=p.second;
}

//cout<<p.first<<" "<<mon<<" "<<ans<<endl;

}


ans+=(max+1-before)*min(x,mon);
    cout<<ans<<endl;
    
}
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PR pair
#define X first
#define Y second

void solve(){
	int n, g;
	cin >> n >> g;
	vector<ii> eve(n*2);
	FOR(i, 0, n){
		int a, b, c;
		cin >> a >> b >> c;
		eve.PB({a, c}), eve.PB({b+1, -c});
	}
	sort(eve.begin(), eve.end());
	int last = 0;
	ll ans = 0, akt = 0;
	TRAV(x, eve){
		ans += min(akt, 1ll*g) * (x.X-last);
		last = x.X;
		akt += x.Y;
	}
	cout << ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt; cin >> tt;
	// FOR(te, 0, tt){
	// 	// cout << "Case #" << te+1 << ": ";
	// 	solve();
	// }
	solve();
	return 0;
}
