#ifndef SEREGA
#include <bits/allocator.h>
#pragma GCC target("avx2,popcnt")
#pragma GCC optimize("O3,no-stack-protector")
#endif
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if (k == 1) {
        int mx = -123;
        for (int i = 0; i < n; ++i) {
            mx = max(mx, a[i] + i + 1);
        }
        cout << mx << endl;
        return;
    }
    if (n == 1) {
        cout << a[0] + 1 << endl;
        return;
    }
    int mx = -1;
    int secondmx = -2;
    for (int i= 0; i < n; ++i) {
        if (a[i] > mx) {
            secondmx = mx;
            mx = a[i];
        } else if (a[i] > secondmx) {
            secondmx = a[i];
        }
    }
    vector<int> all;
    int grabbed = false;
    int mxall = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == mx && !grabbed++) {
            continue;
        }
        all.push_back(a[i]);
        mxall = max(mxall, a[i] + (int)all.size());
    }
    int answer = mxall + mx + 1;
    cout << answer << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) solve();
}