#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define itn int
#define int long long
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define pii pair<int, int>
#define ff first
#define ss second
#define sz(a) (int)(a).size()
#define ll long long
#define ld long double

mt19937 rnd(time(0));

vector <int> c;
vector<int> a;
int ans = 0;

void gen(int i, int n, int k){
    if (i == n){
        vector <vector <int>> mx(k);
        for (int j = 0; j < n; ++j){
            mx[c[j]].push_back(j);
        }
        for (int j = 0; j < k; ++j){
            if (mx[j].empty()){
                return;
            }
        }
        int cur = 0;
        for (itn j = 0; j < k; ++j){
            int m = 0;
            for (int x = 0; x < sz(mx[j]); ++x){
                m = max(m, a[mx[j][x]] + x + 1);
            }
            cur += m;
        }
        ans = max(ans, cur);
        return;
    }
    for (int j = 0; j < k; ++j){
        c.push_back(j);
        gen(i + 1, n, k);
        c.pop_back();
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    a.resize(n);
    for (auto &x: a)  cin >> x;

    gen(0, n, k);

    cout << ans << '\n';
}

signed main(){
    cin.tie(nullptr) ->sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
//    cin >> t;
    while (t--){
        solve();
    }
}