#include <bits/stdc++.h>

using ll = long long;

using namespace std;

#define int ll

int n, k;
vector<int> a, cnt, cost;
int ans;

void rec(int i) {
    if (i == n) {
        ans = max(ans, accumulate(cost.begin(), cost.end(), int(0)));
        return;
    }
    for (int j = 0; j < k; j++) {
        cnt[j]++;
        int prev = cost[j];
        cost[j] = max(cost[j], a[i] + cnt[j]);
        rec(i + 1);
        cnt[j]--;
        cost[j] = prev;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    // int n, k;
    cin >> n >> k;
    a.resize(n);
    cnt.resize(k);
    cost.resize(k);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    rec(0);
    cout << ans;

    cout << "\n";
    return 0;
}