#include <bits/stdc++.h>

using namespace std;

int n, k;
vector<int> a;
vector<int> used;
vector<int> p;
vector<int> num;

long long final_ans = 0;

void rec(int i, int last){
    if (i > n){
        if (last > 0) return;
        /*cout << "new permutation: " << endl;
        for (int j = 1; j <= n; ++j)
            cout << p[j] << " ";
        cout << endl;*/

        vector<int> counted(n + 1);
        long long ans = 0;
        for (int j = n; j >= 1; --j){
            if (counted[j]) continue;
            counted[j] = 1;
            int y = j;
            int temp = num[y] + a[y];
            while (y > 0){
                counted[y] = 1;
                temp = max(temp, num[y] + a[y]);
                y = p[y];
            }
            ans += temp;
            //cout << "j = " << j << ":  " << temp << endl;
        }
        //cout << "ans = " << ans << endl << endl;
        final_ans = max(final_ans, ans);
        return;
    }
    if (last > 0){
        p[i] = 0;
        num[i] = 1;
        rec(i + 1, last - 1);
    }
    for (int j = 1; j < i; ++j){
        if (!used[j]){
            used[j] = 1;
            p[i] = j;
            num[i] = num[j] + 1;
            rec(i + 1, last);
            used[j] = 0;
        }
    }
}

int main()
{
    cin >> n >> k;
    a.resize(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    /*used.resize(n + 1);
    p.resize(n + 1);
    num.resize(n + 1);

    rec(1, k);

    cout << final_ans << endl;*/

    vector<int> s = a;

    sort(s.begin(), s.end());
    int crit = s[n - k + 1];

    /*long long ans = k;
    for (int i = 1; i <= k; ++i){
        ans += a[i];
    }

    cout << ans << endl;
    return 0;*/

    int maxpos = 0;
    for (int i = 1; i <= n; ++i){
        if (a[i] >= crit)
            maxpos = i;
    }
    //cout << "maxpos = " << maxpos << endl;

    /*if (maxpos == n){
        long long ans = n;
        for (int i = n - k + 1; i <= n; ++i){
            //cout << "head "  << s[i] << endl;
            ans += s[i];
        }

        cout << ans << endl;
    }
    else{*/
        long long ans = 0;
        for (int i = n - k + 2; i <= n; ++i){
            ans += s[i] + 1;
        }

        int j = 1;
        int add = 0;
        for (int i = 1; i <= n; ++i){
            if (binary_search(s.begin(), s.begin() + n - k + 2, a[i])){
                //cout << j << ":  " << a[i] << endl;
                add = max(add, a[i] + j);
                ++j;
            }
        }

        ans += add;
        cout << ans << endl;
    //}

    return 0;
}


/*
5 2
1 2 5 4 3

7 2
1 100 30 12 43 4 1

20 2
182 133 185 21 94 46 166 6 122 108 82 46 125 6 95 17 110 169 6 184
*/
