#include <bits/stdc++.h>
#include <bits/extc++.h>

#ifndef LOCAL
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unrool-looops")
#endif

std::random_device rd;
std::mt19937_64 gen(rd());

using namespace __gnu_pbds;
using ll = long long;

template<class T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e3;

std::array<int, N> a;
std::array<bool, N> used;

void not_main() {
    int n, k;
    std::cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    ll ans = n;
    int cnt = 0, del = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (used[i]) {
            continue;
        }
        used[i] = true;
        std::vector<std::pair<int, int>> unused;
        for (int j = 0; j < i; ++j) {
            if (!used[j]) {
                unused.emplace_back(a[j], j);
            }
        }
        ++del;
        ++cnt;
        ans += a[i];
        std::ranges::sort(unused);
        for (auto &[val, ind] : unused) {
            if (n - del - 1 >= k - cnt) {
                ++del;
                used[ind] = true;
            }
        }
    }
    std::cout << ans << '\n';
}

signed main() {
    std::ios_base::sync_with_stdio(false);
#ifndef LOCAL
    std::cin.tie(nullptr);
#endif
    int tests = 1;
    // std::cin >> tests;
    while (tests--) {
        not_main();
    }
    return 0;
}