		ll n, k; cin >> n >> k;

		vector<ll>a(n);
		vector<ll>mem(k);
		vector<ll> dist(k, 0);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		ll cnt = 0;
		for (int i = 0; i < n; ++i) {
			ll best = -100000000000, ind = -1;

			for (int j = 0; j < k; ++j) {
				if (best < (a[i] + dist[j] + 1 + cnt) - mem[j]) {
					ind = j;
					best = (a[i] + dist[j] + 1 + cnt) - mem[j];
				}
			}
			if (ind != -1) {
				mem[ind] = max(mem[ind], a[i] + dist[ind] + 1 + cnt);
				dist[ind]++;
			} else {
				cnt++;
			}
		}
		ll ans = 0;
		sort(mem.rbegin(), mem.rend());
		for (int i = 0; i < k; ++i) {
			ans += mem[i];
		}

}