/*
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
*/
#include<bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define ll long long
#define db double
#define ull unsigned long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int a[maxn],b[maxn],c[maxn];

int main()
{
    fastio();
    int n,k; cin >> n >> k;
    vector<pii_> g;
    rep(i,1,n){
        cin >> a[i] >> b[i] >> c[i];
        g.pb(mp_(a[i],c[i]));
        g.pb(mp_(b[i]+1,-c[i]));
    }
    sort(ALL(g));
    ll ans = 0,tot = 0;
    rep(i,0,2*n-1){
        int now = g[i].fi;
        tot += g[i].se;
        int pos = i;
        while(pos+1<2*n && g[pos+1].fi==now){
            tot += g[++pos].se;
        }
        if(pos == 2*n-1) break;
        ans += 1LL*min(1LL*k,tot)*(g[pos+1].fi-now);
        i = pos;
    }
    cout << ans << endl;
    return 0;
}

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <ios>
#include <iostream>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>
#include <list>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, char> origin,
               std::pair<int64_t, int64_t> another) {
  return origin.first < another.first;
}
bool sort_pair2(std::pair<int64_t, char> origin,
               std::pair<int64_t, int64_t> another) {
  return origin.second < another.second;
}

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

int main()
{
    int64_t q,k,h,w,m,n,c;
    std::cin>> n;
    std::cin>> c;
    std::vector< std::pair< int64_t, int64_t > > list;
    
    for( int i = 0; i < n; i++ )
    {
        std::cin>> q;
        std::cin>> k;
        std::cin>> h;

        list.push_back( std::make_pair( q, h ) );
        list.push_back( std::make_pair( k + 1, -h ) );
    }

    std::sort( list.begin(), list.end(), sort_pair );

    q = 0;
    k = 1;
    m = 0;
    for( int i = 0; i < list.size(); i++ )
    {
        if( k != list[i].first )
        {
            q += std::min( c, m ) * ( list[i].first - k );
            k = list[i].first;
        }

        m += list[i].second;
    }

    std::cout<< q <<"\n";
}

