#pragma GCC optimize("Ofast")

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

typedef long long ll;

#define len(x) (int)x.size()
#define all(x) x.begoin(), x.end()
const ll INF = 1e18;
const int INFi = 1e9;

#define int long long

const int N = 1e5 + 10;

int a[N];

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

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

    int j = 0, ans = -INFi;
    while(j < n - 1 && a[j] == a[0]) ++j;
    for (int i = j + 1; i < n; ++i) {
        ans = max(ans, a[0] + j + a[i] + (i - j + 1));
    }

    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w", stdout);
#endif

    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }

    return 0;
}