#include <bits/stdc++.h>

using namespace std;

void solve(){
	int n;
	long long c;
	cin>>n>>c;
	vector<long long> a(n),b(n);
	vector<long long> c1(n);
	set<int> s;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c1[i];
		s.insert(a[i]);
		s.insert(b[i]+1);
	}
	map<long long,long long> m;
	vector<long long> rev(2*n+1);
	int cord = 0;
	for(auto el: s){
		rev[cord] = el;
		m[el] = cord++;
	}
	vector<long long> p(cord+5);
	for(int i=0;i<n;i++){
		p[m[a[i]]] += c1[i];
		p[m[b[i]+1]] -= c1[i];
	}
	long long cost =min(c, p[0]);
	for(int i=1;i<cord;i++){
		cost += min(p[i-1],c)*(rev[i]-rev[i-1]-1);
		p[i] += p[i-1];
		cost += min(p[i], c);
	}
	cout<<cost<<"\n";
}

int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	int t;
	// cin>>t;
	t = 1;
	while(t--){
		solve();
	}
}
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>
#include <bitset>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define rep1(i, n) for(ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define foreach(i, itr) for(auto& i : (itr))
// 小さい順
#define asort(arr, size) std::sort((arr), (arr) + (size))
// 大きい順
#define dsort(arr, size) std::sort((arr), (arr) + (size), [](auto a, auto b) { return a > b; })
#define vsort(vec) std::sort((vec).begin(), (vec).end());
#define rsort(vec) std::sort((vec).begin(), (vec).end(), [](auto a, auto b) { return a > b; });
#define bit(n) (1LL << (n))

// 行数多く出力するとき用

inline void println(int n) {
    printf("%d\n", n);
}
inline void println(ll n) {
    printf("%lld\n", n);
}
inline void println(ull n) {
    printf("%llu\n", n);
}

inline void println(int* n, size_t size) {
    FOR(i, 0, size - 1) {
        printf("%d ", n[i]);
    }
    printf("%d\n", n[size - 1]);
}
inline void println(ll* n, size_t size) {
    FOR(i, 0, size - 1) {
        printf("%lld ", n[i]);
    }
    printf("%lld\n", n[size - 1]);
}
inline void println(ull* n, size_t size) {
    FOR(i, 0, size - 1) {
        printf("%llu ", n[i]);
    }
    printf("%llu\n", n[size - 1]);
}


////////////////////////////////////
////////////////////////////////////

int main() {
    ll N, C;
    cin >> N >> C;
    vector<pair<ll, ll>> events;
    rep(i, N) {
        ll a, b, c;
        cin >> a >> b >> c;
        events.emplace_back(a - 1, c);
        events.emplace_back(b, -c);
    }
    vsort(events);

    ll ans = 0, fee = 0, t = 0;
    foreach(event, events) {
        if (event.first != t) {
            ans += min(C, fee) * (event.first - t);
            t = event.first;
        }
        fee += event.second;
    }
    cout << ans << endl;

    return 0;
}