#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T>
istream& operator>>(istream& in, vector<T>& arr) {
    for (ll i = 0; i < (ll)arr.size(); ++i) {
        in >> arr[i];
    }
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T>& arr) {
    for (auto el : arr) {
        out << el << " ";
    }
    return out;
}

vector<vector<ll>> g;
vector<bool> used;
vector<ll> dist;

void dfs(ll v) {
    used[v] = true;
    for (auto u : g[v]) {
        if (!used[u]) {
            dist[u] = dist[v] + 1;
            dfs(u);
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> arr(n);
    cin >> arr;
    if (n == k) {
        ll sum = 0;
        for (auto el : arr) {
            sum += el;
        }
        cout << sum + n;
        return 0;
    }
    if (n == 2) {
        cout << max(arr[0] + 1, arr[1] + 2);
        return 0;
    }
    vector<vector<ll>> all(k);
    vector<bool> used(k);
    if (n == 3) {
        ll ans = 0;
        for (ll a = 0; a < k; ++a) {
            for (ll b = 0; b < k; ++b) {
                for (ll c = 0; c < k; ++c) {
                    used[a] = used[b] = used[c] = 1;
                    bool fl = 1;
                    for (ll i = 0; i < k; ++i) {
                        fl &= used[i];
                    }
                    if (fl) {
                        all[a].push_back(0);
                        all[b].push_back(1);
                        all[c].push_back(2);
                        ll curr = 0;
                        for (ll i = 0; i < k; ++i) {
                            ll cur = 0;
                            for (ll j = 0; j < (ll)all[i].size(); ++j) {
                                cur = max(cur, arr[all[i][j]] + j + 1);
                            }
                            curr += cur;
                        }
                        all[a].pop_back();
                        all[b].pop_back();
                        all[c].pop_back();
                        ans = max(ans, curr);
                    }
                    used[a] = used[b] = used[c] = 0;
                }
            }
        }
        cout << ans;
        return 0;
    } else if (n == 4) {
        ll ans = 0;
        for (ll a = 0; a < k; ++a) {
            for (ll b = 0; b < k; ++b) {
                for (ll c = 0; c < k; ++c) {
                    for (ll d = 0; d < k; ++d) {
                        used[a] = used[b] = used[c] = used[d] = 1;
                        bool fl = 1;
                        for (ll i = 0; i < k; ++i) {
                            fl &= used[i];
                        }
                        if (fl) {
                            all[a].push_back(0);
                            all[b].push_back(1);
                            all[c].push_back(2);
                            all[d].push_back(3);
                            ll curr = 0;
                            for (ll i = 0; i < k; ++i) {
                                ll cur = 0;
                                for (ll j = 0; j < (ll)all[i].size(); ++j) {
                                    cur = max(cur, arr[all[i][j]] + j + 1);
                                }
                                curr += cur;
                            }
                            all[a].pop_back();
                            all[b].pop_back();
                            all[c].pop_back();
                            all[d].pop_back();
                            ans = max(ans, curr);
                        }
                        used[a] = used[b] = used[c] = used[d] = 0;
                    }
                }
            }
        }
        cout << ans;
        return 0;
    } else if (n == 5) {
        ll ans = 0;
        for (ll a = 0; a < k; ++a) {
            for (ll b = 0; b < k; ++b) {
                for (ll c = 0; c < k; ++c) {
                    for (ll d = 0; d < k; ++d) {
                        for (ll e = 0; e < k; ++e) {
                            used[a] = used[b] = used[c] = used[d] = used[e] = 1;
                            bool fl = 1;
                            for (ll i = 0; i < k; ++i) {
                                fl &= used[i];
                            }
                            if (fl) {
                                all[a].push_back(0);
                                all[b].push_back(1);
                                all[c].push_back(2);
                                all[d].push_back(3);
                                all[e].push_back(4);
                                ll curr = 0;
                                for (ll i = 0; i < k; ++i) {
                                    ll cur = 0;
                                    for (ll j = 0; j < (ll)all[i].size(); ++j) {
                                        cur = max(cur, arr[all[i][j]] + j + 1);
                                    }
                                    curr += cur;
                                }
                                all[a].pop_back();
                                all[b].pop_back();
                                all[c].pop_back();
                                all[d].pop_back();
                                all[e].pop_back();
                                ans = max(ans, curr);
                            }
                            used[a] = used[b] = used[c] = used[d] = used[e] = 0;
                        }
                    }
                }
            }
        }
        cout << ans;
        return 0;
    } else if (n == 6) {
        vector<vector<ll>> opt;
        ll ans = 0;
        for (ll a = 0; a < k; ++a) {
            for (ll b = 0; b < k; ++b) {
                for (ll c = 0; c < k; ++c) {
                    for (ll d = 0; d < k; ++d) {
                        for (ll e = 0; e < k; ++e) {
                            for (ll f = 0; f < k; ++f) {
                                used[a] = used[b] = used[c] = used[d] = used[e] = used[f] = 1;
                                bool fl = 1;
                                for (ll i = 0; i < k; ++i) {
                                    fl &= used[i];
                                }
                                if (fl) {
                                    all[a].push_back(0);
                                    all[b].push_back(1);
                                    all[c].push_back(2);
                                    all[d].push_back(3);
                                    all[e].push_back(4);
                                    all[f].push_back(5);
                                    ll curr = 0;
                                    for (ll i = 0; i < k; ++i) {
                                        ll cur = 0;
                                        for (ll j = 0; j < (ll)all[i].size(); ++j) {
                                            cur = max(cur, arr[all[i][j]] + j + 1);
                                        }
                                        curr += cur;
                                    }
                                    if (ans < curr) {
                                        opt = all;
                                        ans = curr;
                                    }
                                    all[a].pop_back();
                                    all[b].pop_back();
                                    all[c].pop_back();
                                    all[d].pop_back();
                                    all[e].pop_back();
                                    all[f].pop_back();
                                }
                                used[a] = used[b] = used[c] = used[d] = used[e] = used[f] = 0;
                            }
                        }
                    }
                }
            }
        }
        cout << ans;
        return 0;
    } else if (n == 7) {
        ll ans = 0;
        for (ll a = 0; a < k; ++a) {
            for (ll b = 0; b < k; ++b) {
                for (ll c = 0; c < k; ++c) {
                    for (ll d = 0; d < k; ++d) {
                        for (ll e = 0; e < k; ++e) {
                            for (ll f = 0; f < k; ++f) {
                                for (ll g = 0; g < k; ++g) {
                                    used[a] = used[b] = used[c] = used[d] = used[e] = used[f] = used[g] = 1;
                                    bool fl = 1;
                                    for (ll i = 0; i < k; ++i) {
                                        fl &= used[i];
                                    }
                                    if (fl) {
                                        all[a].push_back(0);
                                        all[b].push_back(1);
                                        all[c].push_back(2);
                                        all[d].push_back(3);
                                        all[e].push_back(4);
                                        all[f].push_back(5);
                                        all[g].push_back(6);
                                        ll curr = 0;
                                        for (ll i = 0; i < k; ++i) {
                                            ll cur = 0;
                                            for (ll j = 0; j < (ll)all[i].size(); ++j) {
                                                cur = max(cur, arr[all[i][j]] + j + 1);
                                            }
                                            curr += cur;
                                        }
                                        all[a].pop_back();
                                        all[b].pop_back();
                                        all[c].pop_back();
                                        all[d].pop_back();
                                        all[e].pop_back();
                                        all[f].pop_back();
                                        all[g].pop_back();
                                        ans = max(ans, curr);
                                    }
                                    used[a] = used[b] = used[c] = used[d] = used[e] = used[f] = used[g] = 0;
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << ans;
        return 0;
    } else if (n == 8) {
        ll ans = 0;
        for (ll a = 0; a < k; ++a) {
            for (ll b = 0; b < k; ++b) {
                for (ll c = 0; c < k; ++c) {
                    for (ll d = 0; d < k; ++d) {
                        for (ll e = 0; e < k; ++e) {
                            for (ll f = 0; f < k; ++f) {
                                for (ll g = 0; g < k; ++g) {
                                    for (ll h = 0; h < k; ++h) {
                                        used[a] = used[b] = used[c] = used[d] = used[e] = used[f] = used[g] = used[h] = 1;
                                        bool fl = 1;
                                        for (ll i = 0; i < k; ++i) {
                                            fl &= used[i];
                                        }
                                        if (fl) {
                                            all[a].push_back(0);
                                            all[b].push_back(1);
                                            all[c].push_back(2);
                                            all[d].push_back(3);
                                            all[e].push_back(4);
                                            all[f].push_back(5);
                                            all[g].push_back(6);
                                            all[h].push_back(7);
                                            ll curr = 0;
                                            for (ll i = 0; i < k; ++i) {
                                                ll cur = 0;
                                                for (ll j = 0; j < (ll)all[i].size(); ++j) {
                                                    cur = max(cur, arr[all[i][j]] + j + 1);
                                                }
                                                curr += cur;
                                            }
                                            all[a].pop_back();
                                            all[b].pop_back();
                                            all[c].pop_back();
                                            all[d].pop_back();
                                            all[e].pop_back();
                                            all[f].pop_back();
                                            all[g].pop_back();
                                            all[h].pop_back();
                                            ans = max(ans, curr);
                                        }
                                        used[a] = used[b] = used[c] = used[d] = used[e] = used[f] = used[g] = used[h] = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << ans;
        return 0;
    }
    ll cnt = k - 1, ans = 0;
    for (ll i = 0; i < cnt; ++i) {
        ans += arr[i] + 1;
    }
    ll cur = 0;
    for (ll i = cnt; i < n; ++i) {
        cur = max(cur, arr[i] + i + 1 - cnt);
    }
    ans += cur;
    ll ans2 = 0;
    ll i = n - 1;
    for (; n - i < cnt; --i) {
        ans2 += arr[i] + 1;
    }
    cur = 0;
    while (i >= 0) {
        cur = max(cur, arr[i] + i + 1);
        --i;
    }
    ans2 += cur;
    cout << max(ans, ans2);
}