#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PLI = pair<long long, long long>;
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;
}
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n, k;
    cin >> n >> k;
    map<ll, ll> mp;
    rep(i, n) {
        ll in;
        cin >> in;
        mp[in]++;
    }
    ll res = 0;
    ll recent = LONG_LONG_MAX;
    rep(i, n + 1) {
        // if (mp[i] >= k) continue;
        if (mp[i] == 0) break;
        chmin(recent, mp[i]);
        res += max(0ll, i + 1) * min(k, recent) - max(0ll, i) * min(k, recent);
        // recent =mp[i];
    }
    cout << res << "\n";
    return 0;
}
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
 
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; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(int i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1,  0};
const vector<int> dy = {0, 1,  0, -1};
 
const vector<int> dx2 = {1, 1,  1, 0,  0, 0, -1, -1, -1};
const vector<int> dy2 = {1, 0, -1, 1, -1, 0,  1,  0, -1};
 
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
 
const ll MAX = 1000000;
const int MOD = 1000000007;
const ll big = (1ll<<60);
 
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
   int a, b;
   cin >> a >> b;
   vector<int>ans;
   if(a>=b){
     int sum = 0;
     rep(i, 0, a){
       ans.push_back(i+1);
       sum += (i+1);
     }
     rep(i, 0, b-1){
       ans.push_back(-(i+1));
       sum -= (i+1);
     }
     ans.push_back(-sum);
   }else{
     int sum = 0;
     rep(i, 0, b){
       ans.push_back(-(i+1));
       sum += (i+1);
     }
     rep(i, 0, a-1){
       ans.push_back(i+1);
       sum -= (i+1);
     }
     ans.push_back(sum);
   }
   for(auto i:ans)cout << i << " ";
   cout << endl;
}