#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//less_equal

//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,bmi2,fma,popcnt")

#define int long long
#define x first
#define y second

int inf = 1'000'000'000'000'000'000;

/*
struct SegTree {
    vector<pair<int, int>> v;
    vector<int> push;

    pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
        return max(a, b);
    }

    void build2(int ind, int l, int r, vector<int>& ve) {
        if (l + 1 == r) {
            v[ind] = {ve[l], l};
            return;
        }
        int mid = (l + r) / 2;
        build2(2 * ind + 1, l, mid, ve);
        build2(2 * ind + 2, mid, r, ve);
        v[ind] = merge(v[2 * ind + 1], v[2 * ind + 2]);
    }

    void build(vector<int>& ve) {
        int n = ve.size();

        v.resize(4 * n);
        push.resize(4 * n, 0);
        build2(0, 0, n, ve);
    }

    void pushh(int ind, int l, int r) {
        if (l + 1 != r) {
            push[2 * ind + 1] += push[ind];
            push[2 * ind + 2] += push[ind];
        }
    }

    void update(int ind, int l, int r, int ql, int qr, int k) {
        pushh(ind, l, r);
    }
};*/

void solve() {
    vector<pair<int, int>> v, v2;
    int n, k;
    cin >> n >> k;
    v.resize(n);
    vector<int> used(n, 1);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first;
        v[i].second = i;
    }
    v2 = v;
    int ans = 0;
    std::sort(v2.begin(), v2.end());
    std::reverse(v2.begin(), v2.end());
    int indmx = 0;
    for (int i = 0; i < k - 1; i++) {
        used[v2[i].second] = 0;
        ans += v2[i].first + 1;
        indmx = max(indmx, v2[i].second);

    }
    indmx = max(indmx, v2[k - 1].second);
    int cnt = 0, mx = 0, cntmx = 0, cntmxx = -1;
    for (int i = 0; i < n; i++) {
        if (used[i]) {
            cnt++;
            if (mx < v[i].first + cnt) {
                mx = max(mx, v[i].first + cnt);
                cntmx = mx;
            }
            if (i >= indmx && cntmxx == -1) {
                cntmxx = cnt - 1;
            }
        }
    }
    //cout << cntmxx + v2[k - 1].first + (v2[k - 1].second < indmx ? 0 : 1) + ans << '\n';
        mx = max(cntmxx + v2[k - 1].first + (v2[k - 1].second < indmx ? 0 : 1), mx);
    cout << ans + mx;
}

signed main() {
#ifdef lisie_bimbi
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
#endif
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
}