#include <bits/stdc++.h>
#define int int64_t
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;



signed main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);


    for (int &i : a)
        cin >> i;
    
    int mx = 0, res = 0;

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

    cout << res;
}