#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const long long INF = 4e18 + 10;
const int maxn = 1 * 1e5 + 5;
const int maxe = maxn;
int a[maxn];
int p[maxn];
int n, m;
bool check(long long t) {
  for (int i = 1; i <= n; ++i) p[i] = a[i];
  int j = n;
  for (int i = 0; i < m; ++i) {
    while (j > 0 && p[j] == 0) --j;
    if (j == 0) return true;
    long long res = t - j;
    if (res <= 0) return false;
    while (j > 0 && res >= p[j]) res -= p[j--];
    if (j > 0) p[j] -= res;
  }
  if (j == 0) return true;
  return false;
}
int MAIN() {
  scanf("%d%d", &n, &m);
  long long lb = -1, rb = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    rb += i + a[i];
  }
  while (rb - lb > 1) {
    long long mid = lb + (rb - lb) / 2;
    if (check(mid))
      rb = mid;
    else
      lb = mid;
  }
  printf("%I64d\n", rb);
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  int ret = MAIN();
  return ret;
}
