#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 5e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, C, cnt; ll ans = 0;
pii d[kN];

int main() { 
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int T = 1; //rd(T);
	while(T--) {
		rd(n, C);
		for(int i = 1; i <= n; ++i) {
			int a, b, c; rd(a, b, c);
			d[++cnt] = mkp(a, c);
			d[++cnt] = mkp(b + 1, -c);
		}
		std::sort(d + 1, d + cnt + 1);
		ll cur_c = 0, ans = 0;
		for(int i = 1; i < cnt; ++i) {
			cur_c += d[i].se;
			ans += std::min(cur_c, (ll)C) * (d[i + 1].fi - d[i].fi);
		}
		printf("%lld\n", ans);
	} return 0;
}
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
    int n,C;
    cin>>n>>C;
    int a[n],b[n],c[n];
    map<int,int> m;
    set<int> s;
    for(int i=0;i<n;i++) {
        cin>>a[i]>>b[i]>>c[i];
        m[a[i]]+=c[i];
        m[b[i]+1]-=c[i];
        s.insert(a[i]);
        s.insert(b[i]+1);
    }
    vector<int> v(s.begin(),s.end());
    int size=v.size();
    int cost=0,ans=0;
    for(int i=0;i<size-1;i++) {
        cost+=m[v[i]];
        ans+=min(cost,C)*(v[i+1]-v[i]);
    }
    cout<<ans;
}
