#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define debug(x) cerr << __LINE__ << ": " << (#x) << " = " << (x) << endl
#else
#define debug(...) 42
#endif

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef __int128 LL;
#define all(x) (x).begin(), (x).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

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

int n, k;
vector<int> a;

ll get(int id, vector<int> &color) {
    if (id == n) {
        vector<ll> now(k, 1), mx(k);
        for (int i = 0; i < n; ++i) {
            mx[color[i]] = max(mx[color[i]], a[i] + now[color[i]]);
            now[color[i]]++;
        }
        if (find(all(now), 1) != now.end()) {
            return 0;
        }
        return accumulate(all(mx), 0ll);
    }
    ll res = 0;
    for (int c = 0; c < k; ++c) {
        color[id] = c;
        res = max(res, get(id + 1, color));
    }
    return res;
}

void solve() {
    vector<int> color(n);
    cout << get(0, color) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    a.resize(n);
    cin >> a;
    solve();
}