#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//template <class T> using ordered_set = tree<T, null_type, less<T>,
//        rb_tree_tag, tree_order_statistics_node_update>;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

mt19937 rnd(time(0));

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0); std::cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <ll> arr(n);
    vector <pair<ll, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        if (i < n - 1) {
            a.push_back({arr[i], i});
        }
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    vector <int> pos;
    for (int i = 0; i < k - 1; i++) {
        pos.push_back(a[i].second);
    }
    sort(pos.begin(), pos.end());
    ll ans = 0, p = -1;
    for (int i = 0; i < k - 1; i++) {
        ans += arr[pos[i]] + (pos[i] - p);
        p = pos[i];
    }
    ll q = 0;
    for (int i = p + 1; i < n; i++) {
        q = max(q, arr[i] + i - p);
    }
    ans += q;
    cout << ans;
    return 0;
}
