#include <bits/stdc++.h>

using namespace std;
#define int int64_t

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++) {
        p[i] = a[i] + i;
    }
    int mx = 0, pos = 0;
    for (int i = 1; i <= n; i++) {
        if (p[i] > mx) {
            mx = p[i];
            pos = i;
        }
    }
    if (pos == 1) {
        int h = 0;
        for (int j = pos + 1; j <= n; j++) {
            h = max(h, a[j] + j - pos);
        }
        cout << mx + h;
        return;
    }
    int y = 0;
    for (int i = 1; i < pos; i++) {
        y = max(y, a[i]);
    }
    y++;
    for (int j = pos + 1; j <= n; j++) {
        y = max(y, a[j] + j - pos + 1);
    }
    mx--;
    cout << mx + y;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
