#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
typedef long long arr[maxn];
void file(int x) {
  if (x && fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
  }
}
arr tmp, a;
int n, m, cnt;
int ch(long long x) {
  memcpy(tmp, a, (n + 1) * sizeof(long long));
  int cnt = n;
  for (int i = 1; i <= m; i++) {
    while (!tmp[cnt] && cnt) cnt--;
    long long ix = x;
    if (ix <= cnt) return 0;
    ix -= cnt;
    while (ix > 0) {
      if (tmp[cnt] > ix) {
        tmp[cnt] -= ix;
        break;
      } else {
        ix -= tmp[cnt];
        tmp[cnt] = 0;
        while (!tmp[cnt] && cnt) cnt--;
        if (!cnt) return 1;
      }
    }
  }
  while (!tmp[cnt] && cnt) cnt--;
  return !cnt;
}
int main() {
  file(1);
  scanf("%d%d", &n, &m);
  long long l = 0, r = 0, md, res;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    r += (1 + a[i]);
  }
  while (l <= r) {
    md = (l + r) >> 1;
    if (ch(md)) {
      res = md;
      r = md - 1;
    } else
      l = md + 1;
  }
  printf("%lld\n", res);
}
