#include <iostream>
#include <set>
#include <vector>
#include <random>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
#define int long long

signed main()
{
    cin.tie(nullptr)->sync_with_stdio(false); 
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<pair<int, int>> pr(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pr[i] = { a[i], i };
    }
    sort(pr.rbegin(), pr.rend());
    vector<bool> used(n);
    int ans = 0;
    int id = -1;
    for (int i = 0; i < k; i++) {
        id = max(id, pr[i].second);
    }
    for (int i = 0; i < k; i++) {
        if (pr[i].second == id) continue;
        ans += pr[i].first + 1;
        used[pr[i].second] = true;
    }
    vector<int> b;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            b.push_back(a[i]);
        }
    }
    int mxv = 0;
    for (int i = 0; i < b.size(); i++) {
        mxv = max(mxv, i + b[i] + 1);
    }
    cout << ans + mxv << '\n';

}