#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
    ll n, m;
    cin >> n >> m;
    vector <ll > a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    multiset <pair <ll, ll > > mst;
    for (ll i = 0; i < m; i++) {
        mst.insert({a[i] + 1, 1});
    }
    ll cnt = 1;
    for (ll i = m; i < n; i++) {
        bool ok = 0;
        for (auto [v, nm] : mst) {
            if (a[i] + nm + cnt >= v) {
                ok = 1;
                auto it = mst.find({v, nm});
                mst.erase(it);
                mst.insert({a[i] + cnt + nm, nm + cnt});
                cnt = 1;
                break;
            }
        }
        if (!ok) {
            cnt++;
        }
    }
    ll ans = 0;
    for (auto e : mst) {
        ans += e.first;
    }
    cout << ans << endl;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    ll z; cin >> z; while(z--)
    solve();
    return 0;
}

/*
5 3
3 7 10 1 2

 5 2
 5 4 3 2 1
*/