#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl
#define NL(x) " \n"[(x)]
#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define mid (l+r)/2
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define lld long long
#define pii pair<int,int>
#define pli pair<lld,int>
#define pil pair<int,lld>
#define pll pair<lld,lld>
#define INF 1000000000
#define LINF 1000000000000000000LL
#define EPS 1e-9
using namespace std;
#define MAXN 200010
map<lld, lld> e;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    lld N, C; cin >> N >> C;
    for(int i = 1; i <= N; i++) {
        lld a, b, c; cin >> a >> b >> c;
        e[a] += c;
        e[b+1] -= c;
    }
    lld cur = 0, pretx = 0;
    lld rez = 0;
    for(auto x : e) {
        lld idx = x.fi, val = x.se;
        rez += min(cur, C)*(idx-pretx);

        cur += val;
        pretx = idx;
    }
    cout << rez;
    return 0;
}

#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
const int INF = 1e9+1;
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {
  ll N, C;
  cin >> N >> C;
  vector<pair<ll, ll>> D;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    D.push_back(make_pair(a-1, c));
    D.push_back(make_pair(b, -c));
  }
  sort(all(D));
  ll ans = 0;
  ll fee = 0;
  ll t = 0;
  for (auto [x, y] : D) {
    if (x != t) {
      ans += min(C, fee)*(x-t);
      t = x;
    }
    fee += y;
  }
  cout << ans << endl;
  return 0;
}