
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  long long int N, C_SUNUKE;
  scanf("%lld %lld", &N, &C_SUNUKE);
  getchar();

  vector<pair<int,int>> events;
  for (int i=0; i < N; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    events.emplace_back(a-1, c);
    events.emplace_back(b, -c);
    getchar();
  }

  sort(events.begin(), events.end());

  long long int cost = 0, total_cost = 0, t = 0;
  for (auto [x,y] : events)
  {
    if (t != x) {
      total_cost += min(cost, C_SUNUKE) * (x-t);
      t = x;
    }
    cost += y;
  }
  cout << total_cost << endl;
}

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

typedef long long ll;

bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
	constexpr ll ll_max = numeric_limits<ll>::max();
 
	bool first_boost = true;
 
	lower_bound = 0;
	upper_bound = x;
	while (upper_bound - lower_bound > 1)
	{
		if (first_boost)
		{
			ll guess = (ll)sqrt((double)x);
			lower_bound = max(guess - 1, (ll)0);
			upper_bound = lower_bound + 3;
			first_boost = false;
		}
 
		ll newval = (lower_bound + upper_bound) / 2;
		if ((newval != 0) && (newval > ll_max / newval))  // newval*newval becomes overflow
			upper_bound = newval;  // because overflow means newval is too big
		else
		{
			ll newval_sqr = newval * newval;
			if (newval_sqr < x)
				lower_bound = newval;
			else
				upper_bound = newval;
		}
	}
 
	if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
	}
	else
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
		else if (upper_bound * upper_bound == x)
			lower_bound = upper_bound;
	}
	bool is_exact = (lower_bound == upper_bound);
	return is_exact;
}

ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);


ll ll_floor(ll x, int digit)
{
	if (x < 0)
		return -ll_ceil(-x, digit);
 
	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	return ans;
}

ll ll_ceil(ll x, int digit)
{
	if (x < 0)
		return -ll_floor(-x, digit);
 
	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	if (modval != 0)
		ans += div;
	return ans;
}
int main() {
	ll N, C;
	cin >> N >> C;

	ll a[N];
	ll b[N];
	ll c[N];

	map<ll, list<ll>> start;
	map<ll, list<ll>> stop;
	unordered_set<ll> visited;
	priority_queue<ll,vector<ll>,greater<ll>> q;

	for (ll i = 0; i < N; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		start[a[i]].push_front(i);
		stop[b[i]].push_front(i);
		if(!visited.count(a[i])){
		q.push(a[i]);
		visited.insert(a[i]);
		}
		if(!visited.count(b[i])){
		q.push(b[i]);
		visited.insert(b[i]);
		}
	}
	
	ll ans = 0;
	ll payPday = 0;
	ll pre=0;
	
	while(!q.empty()){
		ll day = q.top();q.pop();
		ans+=min(payPday, C)*(day-pre-1);
		if(start.count(day)>0){
			for(ll service:start[day]){
				payPday+=c[service];
			}
		}
		ans+=min(payPday, C);
		if(stop.count(day)>0){
			for(ll service:stop[day]){
				payPday-=c[service];
			}
		}
		pre=day;
		
	}

	
	cout << ans << endl;

  return 0;
}