#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
//#include <ext/pb_ds/assoc_containe.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

//template <class T> order_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//find_by_orede, order_of_key

#define int long long
#define all(a) (a).begin(), (a).end()

#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")


const int inf = 1e18;

vector<int> a;
vector<int> cur(10, -inf);
vector<int> sz(10);

int n, k;
int RES = 0;
void f(int i) {
	if (i == n) {
		int sm = 0;
		for (int i = 1; i <= k; ++i)
			if (cur[i] == -inf) return;
			else sm += cur[i];

		RES = max(RES, sm);
		return;
	}

	for (int j = 1; j <= k; ++j) {
		int sv = cur[j]; sz[j]++;

		cur[j] = max(cur[j], a[i] + sz[j]);
		f(i + 1);

		cur[j] = sv; sz[j]--;
	}
}

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

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

	cin >> n >> k;
	a.resize(n);
	for (int& i : a) cin >> i;
	if(n <= 8){
		f(0);
		cout << RES;
		return 0;
	}
}