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