#include <bits/stdc++.h>
int n, m;
long long lb, ub, mid;
long long a[100024];
inline bool C(long long x) {
  int index = n, k = 0;
  long long cur = a[index], tee = x;
  while (index > 0 && k < m) {
    x = tee - index;
    if (x <= 0) return 0;
    while (x >= cur) {
      x -= cur;
      --index;
      if (index < 1) return 1;
      cur = a[index];
    }
    cur -= x;
    ++k;
  }
  if (index > 0) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1), __ = (n); i <= __; ++i) scanf("%I64d", a + i), ub += a[i];
  for (int i = (n), __ = (1); i >= __; --i)
    if (!a[i])
      --n;
    else
      break;
  lb = 0;
  ub += n;
  while (lb <= ub) {
    mid = (lb + ub) >> 1;
    if (C(mid))
      ub = mid - 1;
    else
      lb = mid + 1;
  }
  if (lb > mid) mid = lb;
  if (ub > mid) mid = ub;
  printf("%I64d\n", mid);
  return 0;
}
