#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <array>
using namespace std;
typedef long long ll;
const ll Inf = 1e16;
/*struct SegmentTree {
    struct Node {
        ll sm;
        Node(ll a = 0) { sm = a; }
    };
    vector<Node>tree; ll n;
    SegmentTree(vector<ll>& a) {
        n = a.size(); tree.resize(4 * n);
        build(0, 0, n, a);
    }
    void build(ll v, ll l, ll r, vector<ll>&a) {
        if (r - l == 1) {
            tree[v] = Node(a[l]); return;
        }
        ll mid = (l + r)/2;
        build(2 * v + 1, l, mid, a);
        build(2 * v + 2, mid, r, a);
        tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
    }
    Node merge(Node&a, Node&b) {
        return Node(a.sm + b.sm);
    }
    Node get(ll v, ll l, ll r, ll ind) {
        if (r - l == 1)return tree[v];

    }
};*/
ll ans = -1, n, k;
vector<vector<ll>>answer;
vector<vector<ll>>work;
vector<ll>a;
void rec(ll h) {
    if (h == n) {
        ll res = 0;
        for (int i = 0; i < k; i++) {
            if (work[i].size() == 0)return;
            ll mx = -1;
            for (int j = 0; j < work[i].size(); j++)mx = max(mx, work[i][j] + j + 1);
            res += mx;
        }
        if (ans < res) {
            ans = res;
            answer = work;
        }
        return;
    }
    for (int i = 0; i < k; i++) {
        work[i].push_back(a[h]);
        rec(h + 1);
        work[i].pop_back();
    }
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k; a.resize(n);
    work.resize(k);
    for (int i = 0; i < n; i++)cin >> a[i];
    rec(0);
    cout << ans;
    /*for (auto K : answer) {
        for (auto x : K)cout << x << " ";
            cout << endl;
    }*/
}