#include "bits/extc++.h"

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

template<typename T>
istream &operator>>(istream &is, vector<T> &a);

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a);


using ordered_set = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    cin >> a;

    ll ans = 0;
    for (ll mask = 0; mask < pow(k,n); ++mask) {
        vector<int> block(n);
        ll nmask = mask;
        for (ll i = 0; i < n; ++i) {
            block[i] = nmask % k;
            nmask /= k;
        }
        ll mx = *std::max_element(block.begin(), block.end()) + 1;

        vector<ll > cnt(mx);
        vector<ll> best(mx);
        for (ll i = 0; i < n; ++i) {
            best[block[i]] = max(best[block[i]], ++cnt[block[i]] + a[i]);
        }
        ans=max(ans, std::accumulate(best.begin(), best.end(),0ll));
    }


    cout << ans << "\n";
}

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

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a) {
    for (auto v: a) os << v << " ";
    return (os << "\n");
}
