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

using namespace std;

int main()
{
	int N;
	long long C;
	cin >> N >> C;
	vector<int> a(N), b(N), c(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i] >> c[i];
	}

	vector<int> d;
	for (int i = 0; i < N; ++i) {
		d.push_back(a[i] - 1);
		d.push_back(b[i]);
	}
	sort(d.begin(), d.end());
	d.erase(unique(d.begin(), d.end()), d.end());

	const int D = d.size();

	vector<long long> acc(D + 1, 0LL);

	for (int i = 0; i < N; ++i) {
		auto it_a = lower_bound(d.begin(), d.end(), a[i] - 1);
		auto it_b = lower_bound(d.begin(), d.end(), b[i]);

		acc[it_a - d.begin()] += c[i];
		acc[it_b - d.begin()] -= c[i];
	}

	for (int i = 0; i < D; ++i) {
		acc[i + 1] += acc[i];
	}

	long long ans = 0;
	for (int i = 0; i + 1 < D; ++i) {
		ans += min(C, acc[i]) * (d[i + 1] - d[i]);
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

template<typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    ll n, c;
    cin >> n >> c;
    map<ll, vector<ll>> mp;
    rep(i, n) {
        ll a, b, c;
        cin >> a >> b >> c;
        mp[a].push_back(c);
        mp[b + 1].push_back(-c);
    }
    ll ans = 0;
    ll sum = 0;
    ll now = 1;
    ll prev = now;
    for (auto e : mp) {
        now = e.first;
        ans += min(sum, c) * (now - prev);
        rep(i, e.second.size()) sum += e.second[i];
        prev = now;
    }
    cout << ans << endl;
}