#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define ceil(x, y) ((x)%(y))==0? ((x)/(y)) : ((x)/(y)+1)
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in7.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T=1;
    // cin >> T;
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int N, C; cin >> N >> C;
        /*The only points where some changes happen are ai and bi + 1
        We need to do range update with compressed coordinates
        */
        set<int> st;
        int a[N+1], b[N+1], c[N+1];
        FOR1(i, N){
            cin >> a[i] >> b[i] >> c[i];
            st.insert(a[i]); st.insert(b[i] + 1);
        }

        // coordinate compression
        int idx = 0;
        map<int, int> m;
        for(int pt : st){
            m[pt] = idx;
            idx++;
        }

        // range update on the compressed array -- days
        /*But what does days[i] denote? 
        Index i corresponds to some uncompressed point, p. i+1 corresponds to the next point
        to the right of p, say q.
        days[i] will denote the cost(w/o prime) to avail services in [p, q) 
        */
        int compressed_size = idx;
        assert(m.size() == compressed_size);
        vector<int> days(compressed_size);
        for(int i = 1; i <= N; i++){
            days[m[a[i]]] += c[i];
            if(m[b[i] + 1] < compressed_size) days[m[b[i] + 1]] -= c[i];
        }

        // take prefix-sum and calculate ans
        for(int i = 1; i < compressed_size; i++){
            days[i] += days[i-1];
        }


        int ans = 0;
        /* create a vector from the set of points
        In the compressed days array, we only have the cost values
        but we need to know their duration too i.e decompression
        */
        vector<int> tmp(st.begin(), st.end());
        for(int i = 0; i + 1 < compressed_size; i++){
            int span = tmp[i+1] - tmp[i];
            ans += min(days[i], C) * span;
        }
        cout << ans;
        cout << '\n';
    }
    return 0;
}
//全力以赴
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

int parent[N];
const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};
 
ll gcd(ll a, ll b) { 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
}

ll extGcd(ll a, ll b, ll &x, ll &y) { // solves for x and y where ax+by=gcd(a,b)
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll modInv(ll a, ll p) { // solve for x=a^-1 where ax + py = 1 % p
    if(gcd(a, p) != 1) return -1; // modInv only exists if a and p are coprime (gcd(a, p) = 1)
    ll x, y;
    extGcd(a, p, x, y);
    x = (x % p + p) % p;
    return x;
}
   
ll lcm(ll a, ll b) {  
    return (a * b) / gcd(a,b);  
} 
 
/*
a^b: 
if b is even -> a^b = a^(b/2) * a^(b/2)
if b is odd -> a^b  = a * a^(b-1/2) * a^(b-1/2)
*/
ll modPow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}
 
int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}
 
ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
    }
    return res;
}
 
int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

int msbPos(int n) {
    if(n == 0) return 0;
    int msbPos = 0;
    n /= 2;
    while(n != 0) {
        n /= 2;
        msbPos++;
    }
    return msbPos;
}
 
void solve() {
    int n;
    ll C;
    cin >> n >> C;
    vector<pair<ll, ll>> events;
    for(int i=0;i<n;i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        events.push_back({a, +c});
        events.push_back({b + 1, -c});
    }
    sort(events.begin(), events.end());
    ll res = 0, now = 0, cost = 0;
    int m = events.size();
    for(int i=0;i<m;i++) {
        ll dt = events[i].first - now;
        ll dc = events[i].second;
        res += dt * min(C, cost);

        cost += dc;
        now += dt;
    }
    cout << res << endl;
}

int main()  
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) solve();
    solve();
    return 0; 
}
