#include <bits/stdc++.h>
using namespace std;
int a[100010];
int n, m;
int b[100010];
bool test(long long x) {
  memset(b, 0, sizeof(b));
  int p = 1;
  for (int i = 1; i <= m; i++) {
    long long t = p;
    while (p <= n && t < x) {
      if (x - t >= a[p] - b[p]) {
        t += a[p] - b[p];
        b[p] = a[p];
        p++;
        t++;
      } else if (x - t > 0) {
        b[p] += x - t;
        break;
      } else
        break;
      if (p > n) return true;
    }
    if (p > n) return true;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long L = -1, R = 1LL << 60;
  while (R - L > 1) {
    long long mid = L + (R - L) / 2;
    if (test(mid)) {
      R = mid;
    } else
      L = mid;
  }
  cout << R << endl;
  return 0;
}
