#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long C, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c)
{
    map<ll, ll> zip;
    map<ll, ll> unzip;
    vector<ll> all;
    for (int i = 0; i < N; i++)
    {
        all.push_back(a[i]);
        all.push_back(b[i]);
    }

    SORT(all);
    all.erase(unique(ALL(all)), all.end());
    for (int i = 0; i < all.size(); i++)
    {
        zip[all[i]] = i;
        unzip[i] = all[i];
    }

    vector<ll> sum(all.size() + 1, 0);

    for (int i = 0; i < N; i++)
    {
        sum[zip[a[i]]] += c[i];
        sum[zip[b[i]]] -= c[i];
    }

    for (int i = 0; i < sum.size(); i++)
    {
        sum[i + 1] += sum[i];
    }

    // for (int i = 0; i < sum.size(); i++)
    // {
    //     cout << sum[i] << " ";
    // }
    // cout << endl;

    ll ans = 0;
    for (int i = 0; i < sum.size() - 2; i++)
    {
        // cout << unzip[i] << " " << unzip[i + 1] << " " << sum[i] << endl;
        if (sum[i] > C)
        {
            ans += (unzip[i + 1] - unzip[i]) * C;
        }
        else
        {
            ans += (unzip[i + 1] - unzip[i]) * sum[i];
        }
        // cout << sum[i] << " ";
    }
    // if (sum[sum.size() - 2] > C)
    // {
    //     ans += C;
    // }
    // else
    // {
    //     ans += sum[sum.size() - 2];
    // }
    // cout << endl;

    cout << ans << endl;
}

int main()
{

    long long N;
    scanf("%lld", &N);
    long long C;
    scanf("%lld", &C);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
        scanf("%lld", &c[i]);
        ++b[i];
    }
    solve(N, C, std::move(a), std::move(b), std::move(c));
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
ull inline power(ull a,ull b){ull res = 1;rep(i,b)res *= a;return res;}
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}
string to_oct(int n){string s;while(n){s = to_string(n%8) + s;n /= 8;}return s;}

int main(){
  #define int ll
  int n,c;cin>>n>>c;
  vector<pair<int,int>> a;
  rep(i,n){
    int _a,_b,_c;cin>>_a>>_b>>_c;
    a.push_back(make_pair(_a,_c));
    a.push_back(make_pair(_b+1,-_c));
  }
  sort(all(a));
  
  int crt_day = 0;
  ll ans = 0;
  ll sum = 0;
  for(int i = 0;i < a.size();i++){
    int days = a[i].fi - crt_day;
    if(i != 0 && a[i-1].fi != a[i].fi || i == a.size()-1){
      ans += min(sum, c) * days;  
    }
    sum += a[i].se;
    crt_day = a[i].fi;
  }
  print(ans);
  return 0;
}
