#include <bits/stdc++.h>
int n, m;
int a[100005];
bool check(long long time) {
  int b[100005];
  for (int i = 1; i <= n; i++) {
    b[i] = a[i];
  }
  int cnt = 1;
  for (int i = 0; i < m; i++) {
    while (b[cnt] == 0 && cnt <= n) {
      cnt++;
    }
    if (cnt > n) {
      break;
    }
    long long tmp = cnt;
    while (cnt <= n && b[cnt] + tmp <= time) {
      tmp += b[cnt] + 1;
      b[cnt] = 0;
      cnt++;
    }
    if (tmp < time && cnt <= n) {
      b[cnt] -= time - tmp;
    }
  }
  return cnt > n;
}
int main() {
  std::cin >> n >> m;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    sum += a[i];
  }
  while (a[n] == 0) {
    n--;
  }
  long long l = 1, r = sum + n, ans = 1;
  while (l <= r) {
    long long m = (l + r) / 2;
    if (check(m)) {
      ans = m;
      r = m - 1;
    } else {
      ans = m + 1;
      l = m + 1;
    }
  }
  printf("%lld\n", ans);
}
