#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using ill = long long;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ill n, k;
    cin >> n >> k;
    vector<ill> a(n);
    for (ill i = 0; i < n; i++)
        cin >> a[i];

    ill ans = 0;
    vector<ill> p(8);
    for (ill i0 = 0; i0 < k; i0++)
        for (ill i1 = 0; i1 < k; i1++)
            for (ill i2 = 0; i2 < k; i2++)
                for (ill i3 = 0; i3 < k; i3++)
                    for (ill i4 = 0; i4 < k; i4++)
                        for (ill i5 = 0; i5 < k; i5++)
                            for (ill i6 = 0; i6 < k; i6++)
                                for (ill i7 = 0; i7 < k; i7++) {
                                    vector<vector<ill>> l(k, vector<ill>(0));
                                    l[i0].push_back(a[0]);
                                    if (n > 1)
                                        l[i1].push_back(a[1]);
                                    if (n > 2)
                                        l[i2].push_back(a[2]);
                                    if (n > 3)
                                        l[i3].push_back(a[3]);
                                    if (n > 4)
                                        l[i4].push_back(a[4]);
                                    if (n > 5)
                                        l[i5].push_back(a[5]);
                                    if (n > 6)
                                        l[i6].push_back(a[6]);
                                    if (n > 7)
                                        l[i7].push_back(a[7]);

                                    bool flag = false;
                                    for (ill i = 0; i < k; i++)
                                        if (l[i].size() == 0)
                                            flag = true;
                                    if (flag)
                                        continue;
                                    ill s = 0;
                                    for (ill i = 0; i < k; i++) {
                                        ill mx = 0;
                                        for (ill j = 0; j < l[i].size(); j++)
                                            mx = max(mx, l[i][j] + j + 1);
                                        s += mx;
                                    }
                                    ans = max(ans, s);
                                }
    cout << ans;
}