#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto &x : a) cin >> x;
    vector<ll> tmp(n);
    ll pos = -1, mx = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] >= mx) {
            pos = i + 1;
            mx = a[i];
        }
        tmp[i] = mx + pos;
    }
    pos = -2; mx = -1;
    ll res = 0;
    for (int i = n - 1; i >= 0; --i) {
        pos++;
        if (pos > -1) tmp[i] += mx + pos;
        if (a[i] > mx + pos) {
            pos = 0;
            mx = a[i];
        }
        res = max(res, tmp[i]);
    }
    cout << res << '\n';
}
