#include <bits/stdc++.h>

using namespace std;

#define int long long

int INF = 2e9;
int n, k;
int ans = 0;
vector<int> a;
int sum;

void get(vector<int>& coles) {
    vector<int> cnt(k), op(k);
    sum = 0;
    for (int i = 0; i < n; i++) {
        cnt[coles[i]]++;
        op[coles[i]] = max(op[coles[i]], cnt[coles[i]] + a[i]);
    }
    for (auto to : op) sum += to;
    ans = max(ans, sum);
}



void gen(vector<int>& mas) {
    if (mas.size() == n) {
        get(mas);
        return;
    }
    for (int i = 0; i < k; i++) {
        mas.push_back(i);
        gen(mas);
        mas.pop_back();
    }
}

void sovel() {
    cin >> n >> k;
    a.resize(n);
    for (auto& to: a) cin >> to;
    vector<int> mas;
    gen(mas);
    cout << ans;
}

signed main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        sovel();
    }
}
