#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
long long a[N], tmp[N];
int n, m;
bool check(long long x) {
  for (int i = 1; i <= n; i++) tmp[i] = a[i];
  int pos = n, j = n;
  long long tt;
  for (int i = 1; i <= m; i++) {
    tt = x;
    while (pos >= 1 && tmp[pos] == 0) pos--;
    tt -= pos;
    if (tt < 0) return 0;
    while (j >= 1 && tt - tmp[j] >= 0) tt -= tmp[j], tmp[j] = 0, j--;
    tmp[j] -= tt;
    pos = j;
  }
  while (pos >= 1 && tmp[pos] == 0) pos--;
  return pos == 0;
}
int main() {
  scanf("%d%d", &n, &m);
  long long maxr = 0;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) maxr += a[i];
  long long l = 0, r = 200000000000000;
  long long ans;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
