#include <bits/stdc++.h>
#define ll long long
#define len(x) (int)x.size()
#define ld long double
#define all(x) x.begin(), x.end()
const ll mod1 = 1e9 + 7;

using namespace std;

void print(vector<int> &a){
    for(auto x : a){
        cout << x << ' ';
    }
    cout << '\n';
}

void print(vector<ll> &a){
    for(auto x : a){
        cout << x << ' ';
    }
    cout << '\n';
}

void print(vector<char> &a){
    for(auto x : a){
        cout << x << ' ';
    }
    cout << '\n';
}

void print(vector<string> &a){
    for(auto x : a){
        cout << x << ' ';
    }
    cout << '\n';
}

void print(vector<pair<int, int>> &a){
    for(auto x : a){
        cout << x.first << ' ' << x.second << '\n';
    }
}

void print(vector<vector<int>> &a){
    for(auto x : a){
        print(x);
    }
}

void print(vector<vector<ll>> &a){
    for(auto x : a){
        print(x);
    }
}

//#define int ll
//#define mtask


void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    if(k == 1){
        ll ans = 0;
        for(int i = 0; i < n; ++i){
            ans = max(ans, a[i] + 1ll + i);
        }
        cout << ans << '\n';
        return;
    }
    ll ans = 0;
    {
        vector<int> b(n - 1);
        for(int i = 0; i < n - 1; ++i){
            b[i] = a[i];
        }
        ll curans = n + a[n - 1];
        sort(all(b));
        reverse(all(b));
        for(int i = 0; i < k - 1; ++i){
            curans += b[i];
        }
        ans = curans;
    }
    {
        vector<int> b(n - 1);
        for(int i = 0; i < n - 1; ++i){
            b[i] = a[i];
        }
        ll curans = n - 1;
        sort(all(b));
        reverse(all(b));
        for(int i = 0; i < k; ++i){
            curans += b[i];
        }
        ans = max(ans, curans);
    }
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
#ifdef mtask
    int tt;
    cin >> tt;
    while(tt--);
#endif
    solve();
}