#include <bits/stdc++.h>

using namespace std;

//#define int long long

int INF = 2e9;

vector<int> pr, d;

int get(int v, int l, int r, int ql, int qr) {
    if (l >= qr || ql >= r) {
        return -INF;
    }
    if (ql <= l && r <= qr) {
        return d[v];
    }
    int mid = (l + r) / 2;
    return max(get(v * 2 + 1, l, mid, ql, qr),
    get(v * 2 + 2, mid, r, ql, qr));
}

void build(int v, int l, int r, vector<int>& a) {
    if (r - l == 1) {
        d[v] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    build(v * 2  + 1, l, mid, a);
    build(v * 2 + 2, mid, r, a);
    d[v] = max(d[v * 2 + 2], d[v * 2 + 1]);
}


void sovel() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    for (int i = 0; i < n ; i++) {
        cin >> a[i];
        b[i] = a[i];
        a[i] += i + 1;
    }
    d.resize(n * 4);
    pr.resize(n * 4);
    build(0,0, n, a);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int now = b[i] + 1;
        int sec = get(0, 0, n, 0, i);
        sec = max(get(0, 0, n, i + 1, n) - 1, sec);
        ans = max(ans, now + sec);
    }
    cout << ans;
}

signed main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        sovel();
    }
}
