#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using sll = __int128;

template <typename T>
istream &operator>>(istream &in, pair<T, T> &a){
    in >> a.first >> a.second;
    return in;
}

template <typename T>
ostream &operator<<(ostream &out, pair<T, T> &a){
    out << a.first << ' ' << a.second;
    return out;
}

template <typename T>
istream &operator>>(istream &in, vector<T> &a){
    for(auto &x : a) in >> x;
    return in;
}

template <typename T>
ostream &operator<<(ostream &out, vector<T> &a){
    for(auto x : a) out << x << ' ';
    return out;
}

ll ans = 0;
vector<int> a;

void gen(int ind, vector<int> gr, int n, int k){
    if(ind == n){
        vector<int> cnt(k + 1);
        vector<int> mx(k + 1);
        ll res = 0;
        for(int i = 0; i < n; i++){
            cnt[gr[i]]++;
            mx[gr[i]] = max(mx[gr[i]], a[i] + cnt[gr[i]]);
        }
        for(int i = 1; i <= k; i++){
            if(cnt[i] == 0) return;
            res += mx[i];
        }
        ans = max(ans, res);
        return;
    }
    for (int i = 1; i <= k; i++) {
        gr[ind] = i;
        gen(ind + 1, gr, n, k);
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    a.resize(n);
    cin >> a;
    vector<int> gr(n);
    gen(0, gr, n, k);
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test = 1;
//    cin >> test;
    while(test--){
        solve();
    }
}

