#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define int ll

void solve() {

  int n, k; cin >> n >> k;
  multiset<int, greater<int>> z[k];

  for(int i = 0; i < n; ++i) {
    int x; cin >> x;
    int dt = 0, mx = 0;
    for(int j = 0; j < k; ++j) {
      int d = (x+z[j].size()+1) - (z[j].empty() ? 0 : *z[j].begin());
      if(d > dt) mx = j, dt = d;
    }
    z[mx].insert((x+z[mx].size()+1));
  }

  int res = 0;
  for(int j = 0; j < k; ++j) res += *z[j].begin();

  cout << res << '\n';

  return;
}


signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef pcms2
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif
  // int tt; cin >> tt; while(tt--)
  solve();

  return 0;
}