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

using namespace std;

#define int ll
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using ordered_set = __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

inline void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &x: a) cin >> x;
    auto b = a;
    multiset<int> al;
    sort(rall(b));
    for (int i = 0; i < k; i++) al.insert(b[i]);
    int ans = 0;
    for (auto &x: al) ans += x;
    if (al.find(a.back()) != al.end()) {
        cout << ans + n;
        return;
    }
    al.erase(al.find(b[k - 1]));
    int lst;
    for (int i = n - 1; i >= 0; i--) {
        if (al.find(a[i]) != al.end()) {
            lst = i;
            break;
        }
    }
    ans -= b[k - 1];
    ans += lst + 1;
    int now = 0;
    int mx = 0;
    for (int i = lst + 1; i < n; i++) {
        now++;
        mx = max(mx, a[i] + now);
    }
    ans += mx;
    cout << ans;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}