#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL = (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N, C;
  cin >> N >> C;
  vector<ll> a(N), b(N), c(N);
  REP(i, N) cin >> a[i] >> b[i] >> c[i];
  map<ll, ll> mp;
  REP(i, N) {
    a[i]--;
    b[i]--;
    mp[a[i]] += c[i];
    mp[b[i] + 1] -= c[i];
  }
  ll ans = 0, last_cost = 0, last_day = 0;
  for(auto e : mp) {
    ans += min(last_cost, C) * (e.first - last_day);
    last_cost += e.second;
    last_day = e.first;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back 
#define mp make_pair
#define fi first 
#define se second 
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define LL_MAX LLONG_MAX 
 
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
 
#define mod 1000000007
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
 
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } 
 
int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;} 
 
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;} 
void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" ";  cout<<endl;}  
void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;}
 
#define ms(a,x)  memset(a, x, sizeof(a));
 
#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
 
 
// In binary search always report l-1
 
 
signed main()
{
 
 
      run;
 
 
/* 
open for mod factorial
 
     fac[0]=1;
      for(int i=1;i<1000009;i++)
      {
          fac[i]=mul(fac[i-1],i); 
           
      }
*/
 
 
/*
  for sieve open this and use v_prime 
 
          int pp=pow(10,6)+100000;
               Sieve(pp);
*/
 
 
 // factor(n)  &&   USE v_factor For calculating factors && don't forget v_factor.clear();           
 
 
int  t=1;

while(t--)
{
              map<int,int>mm; // it->second-->frequency
 
 
             int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0,q,z;
             int  h[100009]={0};
 
 
                  cin>>n>>k;
 
 
 
 
            vector<int>a(n,0),b(n,0);
            vector<pair<int,int>>v;
 
            for(i=0;i<n;i++)
            {
              cin>>a[i]>>b[i];
              v.pb(mp(a[i],b[i]));

            }
            sort(all(v));
            for(i=0;i<n;i++)
            {
                a[i]=v[i].fi;
                b[i]=v[i].se;
            }
            

            int prev=0;

        
             

            for(i=0;i<n;i++)
           {
              // cout<<k<<endl;
               if(mm[a[i]]==0)
               {
                    mm[a[i]]++;
               }
               else
               {
                   k+=b[i];
                   continue;
               }
               if(a[i]-prev>k)
               {
                   prev=prev+k;
                   k=0;

                   break;

               }
               else
               {
                   k=k-(a[i]-prev);
                   k+=b[i];

                 //  cout<<k<<endl;

                   prev=a[i];


               }
           }

           prev+=k;
           cout<<prev<<endl;

 
}
}