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

using namespace __gnu_pbds;
using namespace std;

template<class T>
using order_set = tree<T, nullptr_t, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ld = long double;
using mll = map<ll, ll>;
using pll = pair<ll, ll>;
using vll = vector<ll>;

const ll inf = 1e16;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;

const ll nmax = 5e5 + 1;
vector<ll> color;
ll n, k;

void next(ll i) {
    if (i < 0)
        return;
    color[i]++;
    if (color[i] < n)
        return;
    color[i] = 0;
    next(i - 1);
}

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin >> n >> k;
    vector<ll> a(n);
    for (ll &i: a)
        cin >> i;
    color.resize(n);

    ll ans = 0;
    for (ll i = 0; i < pow(n, n); i++) {
        if (set<ll>(color.begin(), color.end()).size() == k) {
            vll res(n);
            vll len(n, 1);
            for (ll j = 0; j < n; j++) {
                res[color[j]] = max(res[color[j]], a[j] + len[color[j]]);
                len[color[j]]++;
            }

            ll sum = 0;
            for (ll j = 0; j < n; j++)
                sum += res[j];
            ans = max(ans, sum);
        }
        next(n - 1);
    }
    cout << ans << '\n';

}