#include <bits/stdc++.h>
const int INF = 100000005;
const int N = 100005;
const int stan = 27;
using namespace std;
long long a[N], b[N], n, m;
long long ans, r;
int CHK(long long x) {
  for (int i = 1; i <= n; i++) b[i] = 0;
  long long las = 1;
  for (int i = 1; i <= m; i++) {
    long long lef = x;
    lef = lef - las + 1;
    for (int j = las; j <= n; j++) {
      lef--;
      las = j;
      if (lef <= 0) break;
      if (lef >= (a[j] - b[j]))
        lef -= a[j] - b[j], b[j] = a[j];
      else {
        b[j] += lef;
        break;
      }
      if (lef <= 0) break;
    }
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  long long l = 0;
  r = 1e18;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (CHK(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
