#include <bits/stdc++.h>
using namespace std;
int n, m, last;
int boxes[100001];
int tmp[100001];
int can_remove(long long int t) {
  long long int st_power;
  int removing, st_no;
  for (int i = 1; i <= last; i++) tmp[i] = boxes[i];
  removing = 1;
  st_no = 1;
  st_power = (t - removing);
  while (removing <= last) {
    if (st_no > m) return 0;
    long long int minv;
    if (st_power < tmp[removing])
      minv = st_power;
    else
      minv = tmp[removing];
    st_power -= minv;
    tmp[removing] -= minv;
    if (st_power <= 0) {
      st_no++;
      st_power = (t - removing);
    }
    if (tmp[removing] <= 0) {
      removing++;
      st_power--;
    }
  }
  return 1;
}
long long int min_time() {
  long long int lo, hi, mid;
  lo = 0;
  hi = 110000000000000;
  for (int i = 0; i < 100; i++) {
    mid = (lo + hi) / 2;
    if (can_remove(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &boxes[i]);
    if (boxes[i] != 0) last = i;
  }
  cout << min_time() << endl;
  return 0;
}
