/*  **    ** ******    ****** ****** **     ******    ***
    **    ** **  **    **  ** **  ** **     **  ** *********
    **\../** ******    ****** **  ** ****** **  **    ***
    **    ** ** **     ** **  **  ** **  ** **  **    *****
    **    ** **  ** ** **  ** ****** ****** ******    *****
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define vt vector 
#define sz(v) ((int)((v).size()))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)2e9;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	for(auto& a:x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	for(auto& a:x)
		read(a);
}

void _run(){
	int n;
	ll c;
	read(n,c);
	map<ll,ll>mp;
	lp(i,n){
		ll a,b,C;
		read(a,b,C);
		mp[a]+=C;
		mp[b+1]-=C;
	}
	int last =0;
	ll sum =0;
	pair<ll,ll>pre;
	for(auto &x:mp){
		if(!last){
			pre=x;
			last = 1;
			continue;
		}
		x.sc+=pre.sc;
		pre=x;
	}
	last =0;
	for(auto x:mp){
		if(!last){
			pre=x;
			last=1;
			continue;
		}
		sum+=(x.fr-pre.fr)*min(c,pre.sc);
		pre=x;
	}
	cout<<sum<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
	init();
    int t=1;
    // read(t);
    while(t--)_run();
    
    return 0;
}
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

using ll = long long;

struct event {
    ll t, c;
};

int main()
{
    ll n, c;
    std::cin >> n >> c;
    std::vector<event> events;
    for (int i = 0; i < n; i++) {
        event a, b;
        std::cin >> a.t >> b.t >> a.c;
        b.t++;
        b.c = -a.c;
        events.push_back(a);
        events.push_back(b);
    }
    std::sort(events.begin(), events.end(), [](const event& a, const event& b) -> bool {
        return a.t < b.t;
    });
    ll ans = 0;
    ll prev = 0;
    ll cur = 0;

    for (auto&& e : events) {
        if (e.t != prev) {
            ans += std::min(c, cur) * (e.t - prev);
            prev = e.t;
        }
        cur += e.c;
    }
    std::cout << ans << "\n";
    return 0;
}
