#include <bits/stdc++.h>
using namespace std;
template<typename T> using vec = vector<T>;
template<typename K, typename V> using umap = unordered_map<K, V>;
using ll = long long;
using ld = long double;
using str = string;
using pll = pair<ll, ll>;
using vll = vec<ll>;
using vi = vec<int>;
using vs = vec<str>;
using mapll = map<ll, ll>;
using umapll = umap<ll, ll>;
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, l, r) for (ll i = ll(l); i < ll(r); i++)
#define _get_rep(_1, _2, _3, NAME, ...) NAME
#define rep(...) _get_rep(__VA_ARGS__, _repi, _rep) (__VA_ARGS__)
#define rrep(i, n) for (ll i = ll(n) - 1; 0 <= i; i--)
#define each(v) for (auto v)
#define all(x) x.begin(), x.end()
#define mkpair make_pair
#define is_in(x, l, r) ((l) <= (x) && (x) < (r))
#define read(t, ...) t __VA_ARGS__; isin(cin, __VA_ARGS__)
#define readv(t, v, n) vec<t> v(n); isin(cin, v)
#define readv2(t, v, h, w) vec<vec<t>> v(h, vec<t>(w)); isin(cin, v)
#define readvv(t, va, vb, n) vec<t> va(n), vb(n); rep (i, n) { isin(cin, va[i], vb[i]); }
#define readvvv(t, va, vb, vc, n) vec<t> va(n), vb(n), vc(n); rep (i, n) { isin(cin, va[i], vb[i], vc[i]); }
#define print(...) osout(cout, __VA_ARGS__)
#define dbg(...) osout(cerr, __VA_ARGS__)
const ll inf = numeric_limits<ll>::max() / 2;
template<typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return 1; } return 0; }
template<typename T> void sort(vec<T> &v) { sort(all(v)); }
template<typename T> void rsort(vec<T> &v) { sort(all(v), greater<T>()); }
template<typename T> void dec(vec<T> &v) { rep (i, v.size()) v[i]--; }
template<typename T> istream& operator >>(istream &is, vec<T> &v) {
    rep (i, v.size()) { cin >> v[i]; } return is;
}
template<typename T1, typename T2> ostream& operator <<(ostream &os, pair<T1, T2> p) {
    if (&os == &cout) { os << p.first << ' ' << p.second; }
    if (&os == &cerr) { os << '(' << p.first << ", " << p.second << ')'; }
    return os;
}
template<typename T> ostream& operator <<(ostream &os, vec<T> v) {
    if (&os == &cout) { rep(i, v.size() - 1) { os << v[i] << ' '; } os << v[v.size() - 1]; }
    if (&os == &cerr) { os << '['; rep(i, v.size() - 1) { os << v[i] << ", "; } os << v[v.size() - 1] << ']'; }
    return os;
}
void isin(istream &_) {}
template<class S, class... T> void isin(istream &is, S &s, T&... t) {
    is >> s; isin(is, t...);
}
void osout(ostream& os) { os << endl; }
template<class S, class... T> void osout(ostream &os, S s, T... t) {
    os << s; if (sizeof...(t)) os << ' '; osout(os, t...);
}
void solve();

int main() {
    #define PRECISION 0

    cin.tie(0);
    ios::sync_with_stdio(false);
    if (PRECISION) {
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
    solve();
    return 0;
}

void solve() {
  read(ll,N,C);
  readvvv(ll,a,b,c,N);

  vll d;
  umapll m;
  rep(i,N) {
    d.emplace_back(a[i]), d.emplace_back(b[i]+1);
    m[a[i]]+=c[i], m[b[i]+1]-=c[i];
  }
  sort(d);
  d.erase(unique(all(d)),d.end());
  ll e=d.size();

  vll s(e+1);
  rep(i,e) s[i+1]=s[i]+m[d[i]];
  
  ll ans=0;
  rep(i,e-1){
    ans+=min(s[i+1],C)*(d[i+1]-d[i]);
  }
  print(ans);
}

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


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

	long long ans = 0;
	long long cost = 0;
	long long prev = 0;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		long long n = it->first - prev;
		ans += min( C, cost ) * n;
		cost += it->second;
		prev = it->first;
	}

	cout << ans << endl;
}
