#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-9;
const double Exp = 2.718281828459045;
const double pi = 3.1415926535897932;
const double E = 2.7182818284590452354;
const int Max_Bit = 63;
const int INF = 2000000000;
const long long LINF = 1000000000000000007ll;
const int MOD = 10000007;
const int NMAX = 100005;
const int MMAX = 300005;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  int n;
  long long m;
  cin >> n >> m;
  long long a[NMAX];
  long long summa = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    summa += a[i];
  }
  long long left = 2, right = summa + n;
  while (left < right) {
    long long med = (left + right) >> 1;
    long long b[NMAX];
    for (int i = 0; i < n; i++) b[i] = a[i];
    long long cur = n - 1;
    for (int i = 0; i < m; i++) {
      while (cur >= 0 && b[cur] == 0) cur--;
      long long time = med - cur - 1;
      if (time <= 0) break;
      while (cur >= 0 && b[cur] <= time) time -= b[cur--];
      if (cur >= 0) b[cur] -= time;
    }
    if (cur < 0)
      right = med;
    else
      left = med + 1;
  }
  cout << right << endl;
  return 0;
}
