#include <bits/stdc++.h>
using namespace std;
int a[100001], b[100001];
int main() {
  int i, j, k, n, m;
  long long sum = 0;
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 1; i < n + 1; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  long long l = 2, r = n + sum;
  while (l < r) {
    long long mid = (l + r) / 2;
    for (i = 1; i < n + 1; i++) b[i] = a[i];
    long long last = n;
    for (i = 0; i < m; i++) {
      while (last > 0 && (b[last] == 0)) last--;
      long long time = mid - last;
      if (time < 0) break;
      while (time > 0 && last > 0) {
        if (last > 0 && time >= b[last]) {
          time -= b[last];
          b[last] = 0;
          while (last > 0 && b[last] == 0) last--;
        } else {
          b[last] -= time;
          time = 0;
        }
      }
    }
    if (last == 0) {
      r = mid;
    } else
      l = mid + 1;
  }
  printf("%I64d\n", r);
}
