#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << endl;
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) res *= x;
  res %= mod;
  return res;
}

signed main() {
  init();
  ll N, C;
  cin >> N >> C;

  priority_queue<P, vector<P>, greater<P>> q;

  rep(i, N) {
    ll a, b, c;
    cin >> a >> b >> c;
    q.push({a, c});
    q.push({b + 1, -c});
  }

  ll ans = 0;
  ll before_index = 0;
  ll before_value = 0;
  ll now = 0;
  ll value = 0;
  while (!q.empty()) {
    P t = q.top();
    q.pop();
    // debug(t.first);
    // debug(t.second);

    if (now == t.first) {
      value += t.second;
      before_value = value;
      before_index = now;
      continue;
    } else {
      now = t.first;
      value += t.second;
      ll l = now - before_index;
      ans += l * min(C, before_value);
      before_value = value;
      before_index = now;
      // debug(l);
      // debug(ans);
      // ENDL;
    }
  }
  ANS;
  return 0;
}
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int n;
int64_t C;

int minn(int64_t &a, int &b) {
    return (a < b) ? a : b;
}

int main(int argc, const char * argv[]) {
    
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    cin >> n >> C;
    
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    
    set<int> s;
    map<int, int64_t> changes;
    
    
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    
    
    for(int i = 0; i < n; ++i) {
        static_cast<void>(s.insert(a[i])), s.insert(b[i] + 1);
        changes[a[i]] += c[i];
        changes[b[i] + 1] -= c[i];
    }
    
    vector<int> v(s.begin(), s.end());
    
    int m = int(v.size());
    
    int64_t acc = 0;
    
    int64_t ans = 0;
    for(int i = 0; i < m - 1; ++i) {
        acc += changes[v[i]];
        ans += (min(C, acc)) * (v[i + 1] - v[i]);
        
    }

    cout << ans;
    
    
    
    return 0;
}
