#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int ll

const int maxn = 5e5 + 1;
int a[maxn];

void solve() {
    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int mx = a[1] + 1;
    int mxid = 1;
    for (int i = 1; i <= n; i++) {
        if (a[i] + i >= mx) {
            mx = a[i] + i;
            mxid = i;
        }
    }

    int ans = mx;

    int mx2 = 0;

    for (int i = mxid + 1; i <= n; i++) {
        mx2 = max(mx2, a[i] + i - mxid);
    }

    int mx3 = 0;
    for (int i = 1; i < mxid; i++) {
        mx3 = max(mx3, a[i] + 1);
    }
    ans = max(mx + mx2, mx + mx3 - 1);
    cout << ans;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifdef local
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
