#include <bits/stdc++.h>
using namespace std;
long long t, n, m, s, a[100010], sum, l, r, mid;
int i, st;
int validate(long long x) {
  int t = m;
  long long s = 0;
  for (int i = int(1); i < int(st + 1); i++) {
    s += a[i];
    while (s + i > x) {
      s -= x - i;
      t--;
      if (t < 0) {
        return 0;
      }
    }
  }
  if (t == 0) {
    return s <= 0;
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = int(1); i < int(n + 1); i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    if (a[i]) {
      st = i;
    }
  }
  l = st + 1;
  r = sum + st;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (validate(mid)) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << r + 1 << endl;
}
