#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
using namespace std;
using ll = long long;
using lld = long double;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif;
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    set<ll> l, r;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        r.insert(a[i] + i);
    }
    
    ll ans = 0;  
    for (int i = 0; i < n; ++i) {
        r.erase(a[i] + i);
        ll r_ans = 0, l_ans = 0;
        if (!r.empty()) {
            r_ans = *r.rbegin();
        }
        if (!l.empty()) {
            l_ans = *l.rbegin();
        }
        l.insert(a[i] + i + 1);
        ans = max(ans, a[i] + 1 + max(l_ans, r_ans));
    }
    cout << ans;
    /*
    ll msk = (1ll << n);
    ll ans = 0, ans_m = 0;
    for (ll m = 1; m < msk; ++m) {
        ll ans1 = 0, ans2 = 0, cnt1 = 0, cnt2 = 0;
        for (ll i = 0; i < n; ++i) {
            if (m & (1 << i)) {
                cnt1++;
                ans1 = max(ans1, cnt1 + a[i]);
            }
            else {
                cnt2++;
                ans2 = max(ans2, cnt2 + a[i]);
            }
        }
        if (ans1 + ans2 > ans) {
            ans = ans1 + ans2;
            ans_m = m;
        }
    }
    cout << ans << '\n';
    for (int i = 0; i < n; ++i) {
        if (ans_m & (1 << i)) {
            cout << i + 1 << " ";
        }
    }
    cout << '\n';
    for (int i = 0; i < n; ++i) {
        if (!(ans_m & (1 << i))) {
            cout << i + 1 << " ";
        }
    }
    */
}