#define LOCAL
//#define SUKA
#ifdef SUKA
#pragma GCC optimize("O3")
#define GCC optimize("unroll-loops")
#endif
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << x << "\n";
#else
#define debug(x)
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;

ll res(vector<ll> a, ll k) {
    ll n = a.size();
    ll ans = 0;
    vector<ll> vans;
    if (k == 1){
        ll mask = (1 << n)-1;
        ll val = 0;
        vector<ll> neww;
        for (ll i = 0;i<n;i++) {
            if (mask & (1 << i)){
                val = max((ll) val,(ll) a[i] + i + 1 - (ll) neww.size());
            }
            else{
                neww.push_back(a[i]);
            }
        }
        auto tp = res(neww, k-1);
        if (ans < val + tp){
            ans = val + tp;
            vans = neww;
        }
        return ans;
    }
    for (ll mask = 1; mask < (1 << n);mask++) {
        if (__builtin_popcount(mask) > n-k+1) {
            continue;
        }
        ll val = 0;
        vector<ll> neww;
        for (ll i = 0;i<n;i++) {
            if (mask & (1 << i)){
                val = max((ll) val,(ll) a[i] + i + 1 - (ll) neww.size());
            }
            else{
                neww.push_back(a[i]);
            }
        }
        auto tp = res(neww, k-1);
        if (ans < val + tp){
            ans = val + tp;
            vans = neww;
        }
    }
    return ans;
}

/*void solve() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    for (ll i =0 ;i<m;i++) {
        cin >> a[i];
    }
    vector<vector<vector<ll>>> dp(m+1, vector<vector<ll>>(2, vector<ll>(2)));
    for (ll i = 0;i<m;i++) {
        for (ll f1 = 0;f1 < 2;f1++) {
            for (ll f2 = 0;f2 < 2;f2++) {
                ll val1 =
            }
        }
    }
}*/

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0;i<n;i++) {
        cin >> a[i];
    }
    ll idx1 = 0, idx2 = 0;
    for (ll i = 0;i<n;i++) {
        if (a[i] + i + 1 >= a[idx1] + idx1 + 1) {
            idx1 = i;
        }
    }
    for (ll i = 0;i<n;i++) {
        if (i == idx1) continue;
        if (a[i] + i + 1 >= a[idx2] + idx2 + 1) {
            idx2 = i;
        }
    }
    cout << a[idx1] + a[idx2] + max(idx1, idx2) + 2;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }
    //cout << res({1,2,3},1);
}
