#include <bits/stdc++.h>

//#pragma GCC optimize("Ofast")

#define int long long

using namespace std;

const int mod = 1e9 + 7;
const int maxn = 2e5 + 1;
const int inf = 4e18;

struct node {
    int val = 0, add = 0;

    node() = default;
    node(int _val) {
        val = _val;
    }
};

void solve() {
    int n, k; cin >> n >> k;
    vector<int> cnt(k);
    vector<int> ans(k);
    set<pair<int, int>> st;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < k; i++) {
        st.emplace(0, i);
    }
    for (int i = 0; i < n; i++) {
        int sm = st.begin()->first;
        int idx = st.begin()->second;
        st.erase(st.begin());
        st.emplace(max(sm, a[i] + cnt[idx]), idx);
        cnt[idx]++;
        ans[idx] = max(sm, a[i] + cnt[idx]);
    }
    cout << accumulate(ans.begin(), ans.end(), 0ll) << '\n';
}

signed main() {
#ifdef LOCAL
    freopen("../input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tt = 1;
//    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}
