#define _GLIBCXX_DEBUG

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>

#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr ll inf = 1e18;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    multiset<ll> q;
    for (ll &e : a) {
        cin >> e;
        q.insert(e);
    }
    while (q.size() != k) {
        q.erase(q.begin());
    }
    int mx = 0;
    for (int i = 0; i < n; ++i) if (q.find(a[i]) != q.end()) mx = i;
    ll s = mx + 1;
    for (ll const &e : q) s += e;
    ll res = s;

    {
    for (ll &e : a) {
        e++;
    }
    ll s = accumulate(all(a), 0);
    for (int i = k; i < n; ++i) {
        int mn = 0;
        for (int j = 1; j + 1 < a.size(); ++j) if (a[j] < a[mn]) mn = j;
        a.back()++;
        a.erase(a.begin() + mn);
        s = accumulate(all(a), 0);
    }
    res = max(s, res);
    }
    cout << res;
}

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