#include <bits/stdc++.h>
using namespace std;
long long n, m, v[500010], backup[500010];
bool first(long long t) {
  memcpy(v, backup, sizeof(long long) * (n + 1));
  long long id = 0;
  for (long long i = 0; i < m; i++) {
    long long falta = t - id - 1;
    while (falta > 0 && id < n) {
      long long usa = min(falta, v[id]);
      v[id] -= usa;
      falta -= usa;
      if (!v[id]) id++, falta--;
    }
  }
  return id == n;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  long long last = -1;
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i]) last = i;
  }
  n = last + 1;
  memcpy(backup, v, sizeof(long long) * (n + 1));
  long long ini = 0, fim = 1e18, res = fim;
  while (ini <= fim) {
    long long meio = ini + (fim - meio) / 2;
    if (first(meio))
      fim = meio - 1, res = meio;
    else
      ini = meio + 1;
  }
  cout << res << '\n';
  return 0;
}
