#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> cnt(N+1, 0);

    rep(i, N){
        int a; cin >> a;
        cnt[a]++;
    }

    ll ans = 0;
    rep(i, K){
        rep(j, N+1){
            if(cnt[j]) cnt[j]--;
            else{
                ans += j;
                break;
            }
        }
    }

    cout << ans << '\n';
}
/***************************************************************
	File name: D.cpp
	Author: ljfcnyali
	Create time: 2021年01月10日 星期日 20时08分49秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 1e6 + 10;

int n, C, c[maxn], p[maxn], m, ans;
map<int, int> Map;
struct node 
{ 
    int l, r, w;
} a[maxn];

inline int lowbit(int x) { return x & -x; }

inline void add(int pos, int val) { for ( int i = pos; i <= m; i += lowbit(i) ) c[i] += val; }

inline int get(int pos) { int sum = 0; for ( int i = pos; i > 0; i -= lowbit(i) ) sum += c[i]; return sum; } 

signed main()
{
    scanf("%lld%lld", &n, &C);
    REP(i, 1, n) 
    {
        scanf("%lld%lld%lld", &a[i].l, &a[i].r, &a[i].w);
        ++ a[i].r; Map[a[i].l] = Map[a[i].r] = true;
    }
    for ( auto it : Map ) { Map[it.first] = ++ m; p[m] = it.first; } 
    REP(i, 1, n) { add(Map[a[i].l], a[i].w); add(Map[a[i].r], -a[i].w); }
    REP(i, 1, m - 1)
    {
        int val = min(get(i), C);
        ans += val * (p[i + 1] - p[i]);
    }
    printf("%lld\n", ans);
    return 0;
}
