import java.util.Scanner ;
public class Main {
private Scanner scanner;
private Main( Scanner scanner) {
this .scanner = scanner;
}
public static void main
( String [ ] args
) { Main main
= new Main
( new Scanner
( System .
in ) ) ; main.solve ( ) ;
}
private void solve( ) {
int n = scanner.nextInt ( ) ;
int m = scanner.nextInt ( ) ;
int [ ] a = new int [ n] ;
long s = 0 ;
for ( int i = 0 ; i < n; i++ ) s += a[ i] = scanner.nextInt ( ) ;
long l = 2 , r = s + n;
while ( l < r) {
long z = l + r >> 1 ;
int [ ] b = a.clone ( ) ;
int p = n - 1 ;
for ( int i = 0 ; i < m; i++ ) {
while ( p >= 0 && b[ p] == 0 ) p--;
long t = z - p - 1 ;
if ( t <= 0 ) break ;
while ( p >= 0 && b[ p] <= t) t -= b[ p-- ] ;
if ( p >= 0 ) b[ p] -= t;
}
if ( p < 0 ) r = z;
else
l = z + 1 ;
}
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewoKICAgIHByaXZhdGUgU2Nhbm5lciBzY2FubmVyOwoKICAgIHByaXZhdGUgTWFpbihTY2FubmVyIHNjYW5uZXIpIHsKICAgICAgICB0aGlzLnNjYW5uZXIgPSBzY2FubmVyOwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBNYWluIG1haW4gPSBuZXcgTWFpbihuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pKTsKICAgICAgICBtYWluLnNvbHZlKCk7CiAgICB9CgogICAgcHJpdmF0ZSB2b2lkIHNvbHZlKCkgewogICAgICAgIGludCBuID0gc2Nhbm5lci5uZXh0SW50KCk7CiAgICAgICAgaW50IG0gPSBzY2FubmVyLm5leHRJbnQoKTsKICAgICAgICBpbnRbXSBhID0gbmV3IGludFtuXTsKICAgICAgICBsb25nIHMgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBzICs9IGFbaV0gPSBzY2FubmVyLm5leHRJbnQoKTsKICAgICAgICBsb25nIGwgPSAyLCByID0gcyArIG47CiAgICAgICAgd2hpbGUgKGwgPCByKSB7CiAgICAgICAgICAgIGxvbmcgeiA9IGwgKyByID4+IDE7CiAgICAgICAgICAgIGludFtdIGIgPSBhLmNsb25lKCk7CiAgICAgICAgICAgIGludCBwID0gbiAtIDE7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CiAgICAgICAgICAgICAgICB3aGlsZSAocCA+PSAwICYmIGJbcF0gPT0gMCkgcC0tOwogICAgICAgICAgICAgICAgbG9uZyB0ID0geiAtIHAgLSAxOwogICAgICAgICAgICAgICAgaWYgKHQgPD0gMCkgYnJlYWs7CiAgICAgICAgICAgICAgICB3aGlsZSAocCA+PSAwICYmIGJbcF0gPD0gdCkgdCAtPSBiW3AtLV07CiAgICAgICAgICAgICAgICBpZiAocCA+PSAwKSBiW3BdIC09IHQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHAgPCAwKSByID0gejsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgbCA9IHogKyAxOwogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4ocik7CiAgICB9Cn0K