#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long acc[100005];
long long bs2(long long i, long long f, long long v) {
  if (i == f) return i;
  long long mid = (i + f) / 2;
  if (acc[mid] + mid + 1 == v)
    return mid;
  else if (acc[mid] + mid + 1 > v)
    return bs2(i, mid, v);
  else
    return bs2(mid + 1, f, v);
}
bool Ok(long long tme) {
  long long mm = 0;
  long long ac = 0;
  for (long long i = 0; i < m; i++) {
    if (ac >= acc[n - 1]) return true;
    long long ind = bs2(0, n - 1, ac + tme);
    if (ind < mm) return false;
    if (tme - (ind + 1) >= acc[ind]) {
      mm = ind + 1;
    }
    ac += tme - (ind + 1);
  }
  if (ac >= acc[n - 1]) return true;
  return false;
}
long long bs(long long i, long long f) {
  if (i == f) return (Ok(i) ? i : 0);
  long long mid = (i + f) / 2;
  if (Ok(mid)) {
    return bs(i, mid);
  } else
    return bs(mid + 1, f);
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 0; i < n; i++) {
    long long a;
    scanf("%lld", &a);
    if (i == 0)
      acc[i] = a;
    else
      acc[i] = acc[i - 1] + a;
  }
  printf("%lld\n", bs(2, acc[n - 1] + n));
  return 0;
}
