#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using ll = long long;
using namespace __gnu_pbds;
using ord_set = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
//    vector<vector<ll>> dp(n + 1, vector<ll> (k + 1));
//    vector<vector<ll>> p(n + 1, vector<ll> (k + 1));
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= k; j++) {
//            dp[i][j] = max(dp[i - 1][j] - p[i - 1][j], dp[i - 1][j - 1]) + a[i - 1];
//            p[i][j] = a[i - 1];
//        }
//    }
//    cout << dp[n][k] + n;
//    vector<vector<ll>> dp(n + 1, vector<ll>(k + 1));
//    for (int i = 1; i <= n; i++) {
//        for (int j = i - 1; j < i; j++) {
//            for (int h = k; h >= 1; h--) {
//                dp[i][h] = max(dp[j][h] - a[j] + a[i], dp[j][h - 1] + a[i]);
//            }
//        }
//    }
//    cout << dp[n][k] + static_cast<ll>(n);
    ll mx = 0;
    for (int i = 0; i < n - 1; i++) {
        mx = max(mx, a[i]);
    }
    cout << mx + a[n] + n;
}

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