#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 1e3;
double a[MAXN], b[MAXN];
double n, x, y, k, z, t, m, d, c, mod = 1e9 + 7, sum, mx, pos1, pos2, ans, r;
string h, s, l;
pair<long long, long long> pr[MAXN];
vector<long long> v;
bool mark[100][100], pass[MAXN];
char trt[5];
map<char, bool> mrk;
map<long long, long long> mpl, mpr;
char maps[100][100];
bool check(long long x) {
  for (int i = 0; i < n; i++) {
    b[i] = a[i];
  }
  long long time = x, ptr = n - 1;
  for (int i = m - 1; i >= 0; i--) {
    time = x;
    while (ptr >= 0 && b[ptr] == 0) {
      ptr--;
    }
    time -= (ptr + 1);
    while (ptr >= 0 && b[ptr] <= time) {
      time -= b[ptr];
      ptr--;
    }
    if (ptr >= 0) {
      b[ptr] -= time;
    }
  }
  if (ptr < 0) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long e = 1e18, b = -1, mid = 0;
  while (e - b > 1) {
    mid = e + b >> 1;
    if (check(mid)) {
      e = mid;
    } else {
      b = mid;
    }
  }
  cout << e;
}
