#include <bits/stdc++.h>
using namespace std;
long long res = 0;
int n, k;
constexpr int MAXN = 100;
int a[MAXN];
void func(int pos, vector <int> sp){
    if (pos == -1){
        long long nw = 0;
        for (auto v: sp){
            nw += v;
            if (v == 0){
                return;
            }
        }
        res = max(res, nw);
        return;
    }
    for (int i = 0; i < k; i++){
        vector <int> nw = sp;
        nw[i] = max(nw[i], a[pos]);
        nw[i]++;
        func(pos - 1, nw);
    }
}
signed main(){

    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector <int> sp(k, 0);
    func(n - 1, sp);
    cout << res << '\n';
}

