#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using ll = long long;

using namespace std;

using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline void solve() {
    /*ordered_set<ll> s;
    cout << (*s.find_by_order(2)) << endl;
    cout << s.order_of_key(2) << endl;*/
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll ans = 0;
    vector<ll> ts(2, 0);
    vector<ll> th(2, 0);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (ts[0] > a[i] + 1 + th[0]) {
            if (ts[1] < a[i] + 1 + th[1]) {
                ts[1] = a[i] + 1 + th[1];
                th[1]++;
            }
        } else {
            if (ts[1] > a[i] + 1 + th[1]) {
                ts[0] = a[i] + 1 + th[0];
                th[0]++;
            } else {
                if (th[0] > th[1]) {
                    ts[0] = a[i] + 1 + th[0];
                    th[0]++;
                } else {
                    ts[1] = a[i] + 1 + th[1];
                    th[1]++;
                }
            }
        }
    }
    cout << ts[0] + ts[1] << endl;
    vector<vector<ll>> d(n, vector<ll> (k + 1, 0));
    d[0][1] = a[0] + 1;
    for (ll i = 1; i < n; i++) {
        for (ll j = 0; j < k + 1; j++) {

        }
    }
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    ll q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}
