#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int n, k;
vector<vector<int>> b;


void gen(vector<int> a) {
    if ((int) a.size() == n) {
        b.push_back(a);
        return;
    }
    for (int i = 1; i <= k; i++) {
        a.push_back(i);
        gen(a);
        a.pop_back();
    }
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    gen({});
    for (auto vec : b) {
        vector<int> maxi(k + 1), cnt(k + 1);
        int c = 1, flag = 1;
        for (int pos : vec) {
            cnt[pos]++;
            maxi[pos] = max(maxi[pos], a[c] + cnt[pos]);
            c += 1;
        }
        ll res = 0;
        for (int i = 1; i <= k; i++) {
            if (cnt[i] == 0) {
                flag = 0;
                break;
            }
            res += maxi[i];
        }
        if (flag) {
            ans = max(ans, res);
        }
    }
    cout << ans;
}
