#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,sse4")
#define int long long
using namespace std;
void gogo() {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    int suff[n + 2] = {};
    int pref[n + 1] = {};
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        pref[i] = max(pref[i - 1], a[i] + i);
    }
    for (int i = n; i >= 1; i--) {
        suff[i] = max(suff[i + 1], a[i] + i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, a[i] + max(pref[i - 1], suff[i + 1] - 1));
    }
    cout << ans << endl;
}
main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        gogo();
    }
}
//0 62 100(?82) 21
//min 165
//max 183