#include <bits/stdc++.h>
using namespace std;
int a[100005], temp[100005];
long long b[100010];
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int i;
  int M = m;
  int maxcod;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long min = 0;
  long long max = 1e15;
  long long mid;
  while (min < max - 1) {
    mid = (min + max) / 2;
    for (i = 1; i <= m; i++) b[i] = mid;
    for (i = 1; i <= n; i++) temp[i] = a[i];
    int s = 1;
    bool flag = true;
    for (i = 1; i <= n; i++) {
      if (temp[i] == 0) {
        continue;
      }
      if (s > m) {
        flag = false;
        break;
      }
      if (temp[i] + i == b[s]) {
        s++;
        continue;
      }
      if (temp[i] + i < b[s]) {
        b[s] -= temp[i];
        continue;
      }
      temp[i] -= b[s] - i;
      i--;
      s++;
    }
    if (flag == 1) {
      max = mid;
    } else {
      min = mid;
    }
  }
  printf("%lld", max);
}
