#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <map>
#include <random>
#include <chrono>

#define int long long

using namespace std;

struct node{
    int x;
    int lazy;
};

vector<node> t;

mt19937 G(chrono::high_resolution_clock::now().time_since_epoch().count());

void push(int v, int l, int r) {
    if (t[v].lazy == 0) {
        return;
    }
    if (l != r-1) {
        t[2*v + 1].lazy += t[v].lazy;
        t[2*v + 2].lazy += t[v].lazy;
    }
    t[v].x += (r-l)*t[v].lazy;
    t[v].lazy = 0;
}

void upd(int v, int l, int r, int ql, int qr, int x) {
    push(v, l, r);
    if (qr <= l && r <= ql) {
        return;
    }
    if (ql >= l && qr <= r) {
        t[v].lazy += x;
        return;
    }
    int m = (l+r)/2;
    upd(2*v+1, l, m, ql, qr, x);
    upd(2*v+2, m, r, ql, qr, x);
    t[v].x = t[2*v+1].x + t[2*v+2].x;
}

int get(int v, int l, int r, int ql, int qr) {
    push(v, l, r);
    if (qr <= l || ql >= r) {
        return 0;
    }
    if (ql >=l && qr <= r) {
        //t[v].x += (r-l)*t[v].lazy;
        return t[v].x;
    }
    int m = (l+r)/2;
    return get(2*v + 1, l, m, ql, qr) + get(2*v + 2, m, r, ql, qr);
}

vector<int> cols;
int n, k;
int ans = 0;
vector<int> a;
void solve(int i) {
    if (i < n-1) {
        for (int j = 0; j < k; j++) {
            cols[i] = j;
            solve(i+1);
        }
    }
    if (i == n-1) {
        for (int j = 0; j < k; j++) {
            cols[i] = j;
            vector<int> used(k, 0);
            for (int l = 0; l < n; l++) {
                used[cols[l]] = 1;
            }
            bool flag = true;
            for (int l = 0; l < k; l++) {
                if (!used[l]) {
                    flag = false;
                }
            }
            if (flag) {
                vector<int> mx(k, 0);
                vector<int> col(k, 0);
                for (int l = 0; l < n; l++) {
                    col[cols[l]]++;
                    mx[cols[l]] = max(mx[cols[l]], a[l] + col[cols[l]]);
                }
                int d = 0;
                for (int l = 0; l < k; l++) {
                    d+= mx[l];
                }
                ans = max(ans, d);
            }
        }
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    if (n <= 8) {
        cols.resize(n, -1);
        a.resize(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        solve(0);
        cout << ans;
    }
    return 0;
}
