#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T SQR(T a) {
  return a * a;
}
template <class T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (!b) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / _gcd(a, b)) * b;
}
template <typename T>
T POW(T b, T p) {
  T r = 1;
  while (p) {
    if (p & 1) r = (r * b);
    b = (b * b);
    p >>= 1;
  }
  return r;
}
template <typename T>
T BigMod(T b, T p, T m) {
  T r = 1;
  while (p) {
    if (p & 1) r = (r * b) % m;
    b = (b * b) % m;
    p >>= 1;
  }
  return r;
}
template <typename T>
T ModInverse(T n, T m) {
  return BigMod(n, m - 2, m);
}
double DEG(double x) { return (180.0 * x) / (acos(-1.0)); }
double RAD(double x) { return (x * (double)acos(-1.0)) / (180.0); }
template <typename T>
double DIS(T a, T b) {
  return sqrt((double)(SQR(a.first - b.first) + SQR(a.second - b.second)));
}
template <typename T>
T ANGLE(T a, T b) {
  return atan(double(a.second - b.second) / double(a.first - b.first));
}
template <typename T>
int isLeft(T a, T b, T c) {
  return (c.first - a.first) * (b.second - a.second) -
         (b.first - a.first) * (c.second - a.second);
}
template <class T>
void prnt(T v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (!i)
      cout << v[i];
    else
      cout << " " << v[i];
  }
  cout << endl;
}
template <class T>
void BIN(T n) {
  if (!n) {
    printf("\n");
    return;
  }
  BIN(n / 2);
  cout << (n % 2);
}
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
long long n, m, ar[100002 + 2], br[100002 + 5];
bool go(long long p, long long r, long long tm) {
  if (r <= 0 && p >= 1) return 0;
  long long rm = (tm - p);
  long long b = ((br[p] + rm - 1) / rm);
  r = (r - b);
  if (r < 0) return 0;
  long long t = rm - (br[p] % rm);
  if (br[p] % rm == 0) t = 0;
  p--;
  while (br[p] == 0) p--;
  if (p <= 0 && r >= 0) return 1;
  while (p >= 1 && t >= 1) {
    long long sub = min(t, br[p]);
    t -= sub;
    br[p] -= sub;
    if (t == 0) break;
    p--;
  }
  if (p <= 1 && br[1] == 0) return 1;
  return go(p, r, tm);
}
bool OK(long long tm) {
  memcpy(br, ar, sizeof(br));
  return go(n, m, tm);
}
int main() {
  int i, j, k;
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  long long sm = 0LL;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    sm += ar[i];
  }
  while (ar[n] == 0LL) n--;
  long long lo = n + 1, hi = n + sm, ret = hi;
  while (lo <= hi) {
    long long md = (lo + hi) >> 1LL;
    if (OK(md)) {
      ret = md;
      hi = md - 1LL;
    } else
      lo = md + 1LL;
  }
  cout << ret << "\n";
  return 0;
}
