#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <climits>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <string>
#include <queue>
#include <random>


//#pragma GCC optimize("03,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

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

const ll INF = 1e18;

int n, k;
vector<int> col;
vector<int> a;
ll mx = 0;

void gen(int v){
    if (v == n){
        vector<vector<int>> ind(k);
        for (int i = 0; i < n; i++){
            ind[col[i]].push_back(i);
        }
        ll s = 0;
        for (int i = 0; i < k; i++){
            int sz = (int)ind[i].size();
            if (sz == 0) return;
            ll val = 0;
            for (int j = 0; j < sz; j++){
                val = max(val, a[ind[i][j]] + j + 1ll);
            }
            s += val;
        }
        mx = max(mx, s);
        return;
    }
    for (int i = 0; i < k; i++){
        col[v] = i;
        gen(v + 1);
    }
}

void solve() {
    cin >> n >> k;
    col.resize(n);
    a.resize(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    gen(0);
    cout << mx;
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}