#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using li = __int128;
using db = double;
using ld = long double;
using pi = pair <int, int>;
using pll = pair <ll, ll>;
#define all(x) x.begin(), x.end()

mt19937 rnd(time(NULL));

struct V {
    db x;
    db y;
};

V operator+ (const V& a, const V& b) {
    return {a.x + b.x, a.y + b.y};
}
db operator* (const V& a, const V& b) {
    return a.x * b.x + a.y * b.y;
}
db operator^ (const V& a, const V& b) {
    return a.x * b.y - a.y * b.x;
}
V operator* (const V& a, db k) {
    return {a.x * k, a.y * k};
}

ll bin_pow(ll a, ll s, ll mod) {
    ll res = 1;
    while (s) {
        if (s & 1) {
            res *= a;
            res %= mod;
        }
        a = (a * a) % mod;
        s >>= 1;
    }
    return res;
}


void solve() {
    int n, k;
    cin >> n >> k;
    vector <ll> v(n);
    for (auto& i : v) cin >> i;
    vector <pair <ll, int>> max_pref(n + 1), max_suf(n + 1);
    for (int i = 1; i <= n; ++i) {
        max_pref[i] = max(max_pref[i - 1], {v[i - 1], i});
        max_suf[i] = max(max_suf[i - 1], {v[n - i], n - i + 1});
    }
    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        ans = max(ans, v[i - 1] + i +
        max_suf[n - i].first + max_suf[n - i].second - i);
    }
    cout << ans << '\n';
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}
