

#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e9+7;

ll ceildiv(ll a, ll b) { return (a+b-1)/b; } // 切り上げ
ll floordiv(ll a, ll b) { return a/b; } // 切り下げ

int show_matrix(vector<vector<int>> &dp) {
  loop(0, dp.size(), i) {
    loop(0, dp[i].size(), j) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;

  vector<ll> A(N);

  ll mx = 0;
  map<ll, ll> M;
  loop(0, N, i) {
    ll a;
    cin >> a;
    M[a]++;
    mx = max(mx, a);
  }

  ll last = 0;
  ll sum = 0;
  loop(0, mx+1, i) {
    ll v = i;
    ll c = M[i];
    last = v;
    while (K - c > 0 && K > 0) {
      sum += v;
      K--;
    }
    if (K == 0) break;
  }
  sum += (last+1) * K;
  print(sum);
}

#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> count(n+1, 0);
  rep(i, n){
    int a;
    cin >> a;
    count[a]++;
  }
  ll ans = 0;
  rep(i, n+1){
    ll now = k - count[i];
    if (now < 0) now = 0;
    ans += i * now;
    k -= now;
    if (k <= 0) break;
  }
  cout << ans << endl;
  
  return 0;
}