#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//template <class T> using ordered_set = tree<T, null_type, less<T>,
//        rb_tree_tag, tree_order_statistics_node_update>;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

mt19937 rnd(time(0));

ll ans = 0;
vector <ll> a;
int n, k;

void f(vector <vector <ll>> &arr, int p) {
    if (p == n) {
        ll res = 0;
        for (int i = 0; i < k; i++) {
            if (arr[i].empty()) {
                return;
            }
            ll mx = 0;
            for (int j = 0; j < arr[i].size(); j++) {
                mx = max(mx, arr[i][j] + j + 1);
            }
            res += mx;
        }
        ans = max(ans, res);
        return;
    }
    for (int i = 0; i < k; i++) {
        arr[i].push_back(a[p]);
        f(arr, p + 1);
        arr[i].pop_back();
    }
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0); std::cout.tie(0);
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector <vector <ll>> arr(k);
    f(arr, 0);
    cout << ans;
    return 0;
}
