#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using ll = long long;
using namespace __gnu_pbds;
using ord_set = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;
#define int ll
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
//    vector<vector<ll>> dp(n + 1, vector<ll> (k + 1));
//    vector<vector<ll>> p(n + 1, vector<ll> (k + 1));
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= k; j++) {
//            dp[i][j] = max(dp[i - 1][j] - p[i - 1][j], dp[i - 1][j - 1]) + a[i - 1];
//            p[i][j] = a[i - 1];
//        }
//    }
//    cout << dp[n][k] + n;
    int ans = 0;
    for (int mask = 0; mask < pow(k, n); mask++) {
        vector<int> b;
        int x = mask;
        vector<int> used(k);
        int j = 0;
        while (j < n) {
            b.push_back(x % k);
            used[x % k] = 1;
            x /= k;
            j++;
        }
        int cnt = 0;
        for (int i = 0; i < k; i++) cnt += used[i];
        if (cnt < k) {
            continue;
        }
        reverse(b.begin(),b.end());
        used.assign(k, 0);
        int cur = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (!used[b[i]]) {
                used[b[i]] = 1;
                cur += a[i];
            }
        }
        ans = max(ans, cur);
    }
    cout << ans + n;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
//    cin >> tt;
    while (tt--) {
        solve();
    }
}
