#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005];
int x;
int aa(long long mid) {
  int i = 1, z = x, k = a[x];
  long long t;
  while (i <= m) {
    t = mid;
    if (t <= z) return 0;
    t -= z;
    while (t >= k) {
      t -= k;
      z--;
      while (z >= 1 && !a[z]) z--;
      if (z == 0) return 1;
      k = a[z];
    }
    k -= t;
    i++;
  }
  return 0;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i]) x = i;
    }
    long long l = 0, r = 10000000000000000, mid;
    while (l < r) {
      mid = (l + r) / 2;
      if (aa(mid))
        r = mid;
      else
        l = mid + 1;
    }
    printf("%I64d\n", r);
  }
  return 0;
}
