#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll INF = 1e14;
ll MOD = 1e9 + 7;

vector<ll> a;
ll k;

ll rec(ll mask, ll n, ll cnt) {    
    if(mask == 0 || cnt == k) return 0;
    ll res = 0;
    for(ll mask2 = mask;mask2 > 0;mask2 = (mask2 - 1) & mask) {
        ll cn = 0, ans = 0;
        for(ll i = 0;i < n;i++) {
            if((mask2 >> i) & 1) {
                cn++;
                ans = max(ans, cn + a[i]);
            }
        }
        ll x = rec(mask ^ mask2, n, cnt + 1);
        res = max(res, x + ans);
        if(res == 28) {
            cout << 1;
        }
    }
    return res;
}

void solve() {
    ll n;
    cin >> n >> k;
    a.resize(n);
    for(auto &i : a) cin >> i;
    cout << rec((1 << n) - 1, n, 0);
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    ll tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
        cout << '\n';
    }
    return 0;
}