#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int SINF = 1LL << 29;
const ll mod = 1000000000+7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

int main() {
    // N:日, C:プライムの１日の値段
    ll N, C;
    cin >> N >> C;
    // a~b日目の終わりまでサービスを使う, プライムでないときは1日あたり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) {
        mp[a[i]] += c[i];
        mp[b[i]+1] += -c[i];
    }

    vector<pair<ll, ll>> vp;
    for(auto m:mp) {
        vp.push_back(make_pair(m.first, m.second));
    }
    ll X = 0, ans = 0;

    // rep(i, vp.size()){
    //     cout << vp[i].first << " " << vp[i].second << endl;
    // }
    rep(i, vp.size()-1) {
        X += vp[i].second;
        if(X < C) ans += (vp[i+1].first - vp[i].first) * X;
        else ans += (vp[i+1].first-vp[i].first) * C;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<ll,ll> P;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n,0);
    rep(i,n){
        cin >> a[i];
    }
    
    vector<ll> kazu(n+1,0);
    
    rep(i,m){
        kazu[a[i]]++;
    }
    
    ll now;
    
    for(ll i=0;i<=n;i++){
        if(kazu[i]==0){
            now=i;
            break;
        }
    }
    
    for(ll i=0;i<n-m;i++){
        kazu[a[i]]--;
        kazu[a[i+m]]++;
        if(kazu[a[i]]==0&&i<now){
            now=i;
        }
        
    }
    
    cout << now << endl;

    return 0;
}









