import java.io.*;
import java.util.*;

public class CF551C {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int[] aa = new int[n];
		st = new StringTokenizer(br.readLine());
		long sum = 0;
		for (int i = 0; i < n; i++) {
			aa[i] = Integer.parseInt(st.nextToken());
			sum += aa[i];
		}
		long upper = n + (sum - 1) / m + 1;
		long lower = 0;
		while (upper - lower > 1) {
			long t = (long) ((upper + lower) / 2);
			int[] bb = Arrays.copyOf(aa, n);
			int i = n - 1;
			while (i >= 0 && bb[i] == 0)
				i--;
			for (int j = 0; j < m; j++) {
				long s = t - (i + 1);
				while (s > 0 && i >= 0) {
					long min = Math.min(bb[i], s);
					bb[i] -= min;
					s -= min;
					while (i >= 0 && bb[i] == 0)
						i--;
				}
			}
			if (i < 0)
				upper = t;
			else
				lower = t;
		}
		System.out.println(upper);
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Boxes {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	@SuppressWarnings("unused")
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskB implements Solver {

	int[] piles;
	int n, students;

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		n = in.readInt();
		students = in.readInt();
		piles = new int[n];
		for(int i=0;i<n; i++)
			piles[i] = in.readInt();

		out.println(binS(piles[0], (int)(n+10e9)) );

		return;
	}

	int binS( int lo, int hi){
		//int ret = 0;

		while(lo < hi){
			int m = lo + hi >> 1;
			if (fun(m))
				hi = m; // hi = m-1;
			else
				lo = m + 1; // lo = m;
		}

		return lo;
	}

	boolean fun( int time){
		int[] sim = Arrays.copyOf(piles, n);
		int rightmost = n-1;
		while(sim[rightmost]==0){
			rightmost--;
			if(rightmost<0) return false;
		}
		for(int i=0 ; i<students;i++){
			int t = time;
			t-= rightmost+1;
			if(t<=0) break;

			while(t>0 && rightmost>=0){

				if(sim[rightmost]==0){
					rightmost--;
				} else{
					sim[rightmost]--;
					t--;
				}
			}

		}
		for(int i : sim)
			if(i>0) return false;

		return true;
	}

}


import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Boxes {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	@SuppressWarnings("unused")
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskB implements Solver {

	int[] piles;
	int n, students;

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		n = in.readInt();
		students = in.readInt();
		piles = new int[n];
		for(int i=0;i<n; i++)
			piles[i] = in.readInt();

		out.println(binS(0, (int)(n*10e9)) );

		return;
	}

	int binS( int lo, int hi){
		//int ret = 0;

		while(lo < hi){
			int m = lo + hi >> 1;
			if (fun(m))
				hi = m; // hi = m-1;
			else
				lo = m + 1; // lo = m;
		}

		return lo;
	}

	boolean fun( int time){
		int[] sim = Arrays.copyOf(piles, n);
		int rightmost = n-1;
		while(sim[rightmost]==0){
			rightmost--;
			if(rightmost<0) return false;
		}
		for(int i=0 ; i<students;i++){
			int t = time;
			t-= rightmost+1;
			if(t<=0) break;

			while(t>0 && rightmost>=0){

				if(sim[rightmost]==0){
					rightmost--;
				} else{
					sim[rightmost]--;
					t--;
				}
			}

		}
		for(int i : sim)
			if(i>0) return false;

		return true;
	}

}


import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Boxes {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	@SuppressWarnings("unused")
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong(){
		return Long.parseLong(readString());
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskB implements Solver {

	int[] piles;
	int n, students;

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		n = in.readInt();
		students = in.readInt();
		long sum = 0;
		piles = new int[n];
		for(int i=0;i<n; i++)
			sum+= piles[i] = in.readInt();

		out.println(binS(2, (long)(n+sum)) );

		return;
	}

	long binS( long lo, long hi){

		while(lo < hi){
			long m = lo + hi >> 1;
			if (fun(m))
				hi = m; // hi = m-1;
			else
				lo = m + 1; // lo = m;

		}

		return lo;
	}

	boolean fun( long time){
		int[] sim = piles.clone();
		int rightmost = n-1;
		for(int i=0 ; i<students;i++){
			while(rightmost>=0 && sim[rightmost]==0 ) rightmost--;

			long t = time - rightmost - 1;
			if(t<=0) break;

			while(rightmost>=0 && sim[rightmost]<= t)
				t-= sim[rightmost--];

			if(rightmost>=0) sim[rightmost] -= t;
		}
		if(rightmost < 0) return true;
		else return false;
	}

}


import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Boxes {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	@SuppressWarnings("unused")
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskB implements Solver {

	int[] piles;
	int n, students;

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		n = in.readInt();
		students = in.readInt();
		piles = new int[n];
		for(int i=0;i<n; i++)
			piles[i] = in.readInt();

		out.println(binS(piles[0], (int)(n*piles[n-1])) );

		return;
	}

	int binS( int lo, int hi){
		//int ret = 0;

		while(lo < hi){
			int m = lo + hi >> 1;
			if (fun(m))
				hi = m; // hi = m-1;
			else
				lo = m + 1; // lo = m;
		}

		return lo;
	}

	boolean fun( int time){
		int[] sim = Arrays.copyOf(piles, n);
		int rightmost = n-1;
		while(sim[rightmost]==0){
			rightmost--;
			if(rightmost<0) return false;
		}
		for(int i=0 ; i<students;i++){
			int t = time;
			t-= rightmost+1;
			if(t<=0) break;

			while(t>0 && rightmost>=0){

				if(sim[rightmost]==0){
					rightmost--;
				} else{
					sim[rightmost]--;
					t--;
				}
			}

		}
		for(int i : sim)
			if(i>0) return false;

		return true;
	}

}


import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Boxes {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	@SuppressWarnings("unused")
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong(){
		return Long.parseLong(readString());
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskB implements Solver {

	int[] piles;
	int n, students;

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		n = in.readInt();
		students = in.readInt();
		long sum = 0;
		piles = new int[n];
		for(int i=0;i<n; i++)
			sum+= piles[i] = in.readInt();

		out.println(binS(piles[0], (long)(n+sum)) );

		return;
	}

	long binS( long lo, long hi){

		while(lo < hi){
			long m = lo + hi >> 1;
			if (fun(m))
				hi = m; // hi = m-1;
			else
				lo = m + 1; // lo = m;

		}

		return lo;
	}

	boolean fun( long time){
		int[] sim = piles.clone();
		int rightmost = n-1;
		for(int i=0 ; i<students;i++){
			while(rightmost>=0 && sim[rightmost]==0 ) rightmost--;

			long t = time - rightmost - 1;
			if(t<=0) break;

			while(rightmost>=0 && sim[rightmost]<= t)
				t-= sim[rightmost--];

			if(rightmost>=0) sim[rightmost] -= t;
		}
		if(rightmost < 0) return true;
		else return false;
	}

}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static int m;
	static int n;
	static long[] arr;
	static long best = (long) 1e9 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		trythistime();

		System.out.println(best);

	}

	public static boolean isvalid(long time, long arr[]) {
		int lastj = 0;
		int j = 0;
		long[] arry = arr.clone();
		for (int i = 0; i < m; i++) {
			long t = time;
			int last = 0;

			for (j = lastj; j < n && t > 0; j++) {
				// System.out.println(last);
				if (arry[j] > 0) {
					t -= (j + 1 - last);
					last = j + 1;

					while (arry[j] > 0 && t > 0) {
						t -= 1;
						arry[j] -= 1;
					}
				}
			}
			lastj = j - 1;
		}
		long sum = 0;
		for (int i = 0; i < n; i++)
			sum += arry[i];
		return (sum == 0);
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e9 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			// System.out.println(mid);
			if (isvalid(mid, arr)) {
				// System.out.println(mid);
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static int m;
	static int n;
	static long[] arr;
	static long best = (long) 1e9 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		trythistime();
		// System.out.println("CECKKKKK"+isvalid(4,arr));
		// System.out.println(arr[0]);
		System.out.println(best);

	}

	public static boolean isvalid(long time, long arr[]) {

		long[] arry = arr.clone();
		for (int i = 0; i < m; i++) {
			long t = time;
			int last = 0;
			for (int j = 0; j < n && t > 0; j++) {
				// System.out.println(last);
				if (arry[j] > 0) {
					t -= (j + 1 - last);
					last = j + 1;

					while (arry[j] > 0 && t > 0) {
						t -= 1;
						arry[j] -= 1;
					}
				}

			}
		}
		long sum = 0;
		for (int i = 0; i < n; i++)
			sum += arry[i];
		return (sum == 0);
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e9 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			// System.out.println(mid);
			if (isvalid(mid, arr)) {
				// System.out.println(mid);
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static int m;
	static int n;
	static long[] arr;
	static long best = (long) 1e10 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		 trythistime();
		//System.out.println(isvalid(5, arr));
		 System.out.println(best);

	}

	public static boolean isvalid(long time, long arr[]) {
		int j = 0;
		int i = 0;

		long[] arry = arr.clone();
		while (i < m && j < arr.length) {
			long t = time - 1 - j;
			while (t > 0 && j < arr.length) {
				if (arry[j] > 0) {
					if (arry[j] <= t) {
						t -= arry[j];
						arry[j] = 0;

					} else {
						arry[j] -= t;
						t = 0;
					}
				} else {
					j++;
					t--;
				}
			}
			i++;

		}

		for (int k = 0; k < n; k++)
			if (arry[k] != 0)
				return false;
		return true;
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e10 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			if (isvalid(mid, arr)) {
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static int m;
	static int n;
	static long[] arr;
	static long best = (long) 1e9 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		trythistime();
		// System.out.println("CECKKKKK"+isvalid(3,arr));
		// System.out.println(arr[0]);
		System.out.println(best);

	}

	public static boolean isvalid(long time, long arr[]) {
		long[] arry = arr.clone();
		int cont = 0;
		int start = 0;
		outter: for (int i = 0; i < m; i++) {
			long t = time;
			start = cont;
			// System.out.println("STAAAAART"+start);
			if (start > 0)
				t -= (start);
			else if (t <= 0)
				return false;
			// System.out.println(t);
			for (int j = start; j < n && t > 0; j++) {
				// System.out.println(j+"J "+t+" t");
				if (arry[j] > 0) {
					if (t >= 2) {
						t -= 2;
						arry[j] -= 1;
					} else {
						continue outter;
					}

				} else
					t -= 1;
				// System.out.println(t);
				cont = j;
			}

			if (cont == n - 1 && arry[n - 1] == 0)
				return true;
		}
		return false;
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e9 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			// System.out.println(mid);
			if (isvalid(mid, arr)) {
				// System.out.println(mid);
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static long arr[];
	static int m;
	static int n;
	static long best = (long) 1e9 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		trythistime();
		System.out.println(best);

	}

	public static boolean isvalid(long time) {
		int cont = 0;
		int start = 0;
		outter: for (int i = 0; i < m; i++) {
			long t = time;
			start = cont;
			t -= (start);
			if (t <= 0)
				return false;
			// System.out.println(t);
			for (int j = start; j < n && t > 0; j++) {
				// System.out.println(j+"J "+t+" t");
				if (arr[j] > 0) {
					if (t >= 2)
						t -= 2;
					else {
						cont = j;
						continue outter;
					}

				} else
					t -= 1;
				// System.out.println(t);
				cont = j;
			}
			if (cont == n - 1)
				return true;
		}
		return false;
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e9 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			// System.out.println(mid);
			if (isvalid(mid)) {
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static int m;
	static int n;
	static long[] arr;
	static long best = (long) 1e16 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		 trythistime();
		//System.out.println(isvalid(5, arr));
		 System.out.println(best);

	}

	public static boolean isvalid(long time, long arr[]) {
		int j = 0;
		int i = 0;

		long[] arry = arr.clone();
		while (i < m && j < arr.length) {
			long t = time - 1 - j;
			while (t > 0 && j < arr.length) {
				if (arry[j] > 0) {
					if (arry[j] <= t) {
						t -= arry[j];
						arry[j] = 0;

					} else {
						arry[j] -= t;
						t = 0;
					}
				} else {
					j++;
					t--;
				}
			}
			i++;

		}

		for (int k = 0; k < n; k++)
			if (arry[k] != 0)
				return false;
		return true;
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e16 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			if (isvalid(mid, arr)) {
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


import java.io.*;
import java.util.StringTokenizer;

public class GukiZhatesBoxes {
	static int m;
	static int n;
	static long[] arr;
	static long best = (long) 1e9 + 1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		m = sc.nextInt();
		arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		 trythistime();
		//System.out.println(isvalid(5, arr));
		 System.out.println(best);

	}

	public static boolean isvalid(long time, long arr[]) {
		int j = 0;
		int i = 0;

		long[] arry = arr.clone();
		while (i < m && j < arr.length) {
			long t = time - 1 - j;
			while (t > 0 && j < arr.length) {
				if (arry[j] > 0) {
					if (arry[j] <= t) {
						t -= arry[j];
						arry[j] = 0;

					} else {
						arry[j] -= t;
						t = 0;
					}
				} else {
					j++;
					t--;
				}
			}
			i++;

		}

		for (int k = 0; k < n; k++)
			if (arry[k] != 0)
				return false;
		return true;
	}

	public static void trythistime() {
		long lo = 0;
		long hi = (long) (1e9 + 1);
		long mid = 0;
		while (lo <= hi) {

			mid = (lo + hi) >> 1;
			if (isvalid(mid, arr)) {
				if (mid < best)
					best = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(1000);
		}
	}
}


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;
        }
        System.out.println(r);
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		int pileCount = in.nextInt();
		long boxCount = 0;
		int studentCount = in.nextInt();
		int[] boxes = new int[pileCount];

		for (int i = 0; i < pileCount; i++) {
			boxes[i] = in.nextInt();
			boxCount += boxes[i];
		}

		long left = 0;
		long right = boxCount + pileCount;

		while (left != right) {
			long middle = (left + right) / 2;
            // System.out.println(left + "/" + middle + "/" + right);

			if (valid(boxes, boxCount, studentCount, middle)) {
				right = middle;
			} else {
				left = middle + 1;
			}
		}

		System.out.println(left + 1);
	}

	public static boolean valid(int[] boxes, long boxCount, int studentCount, long time) {
		int[] copied = Arrays.copyOf(boxes, boxes.length);
		int nextIndex = 0;

		for (int i = 0; i < studentCount; i++) {
            int currentIndex = nextIndex;
			long timeLeft = time - currentIndex;

			while (timeLeft > 0 && currentIndex < copied.length) {
				long toRemove = Math.min(timeLeft, copied[currentIndex]);

				timeLeft -= toRemove;
				copied[currentIndex] -= toRemove;
				boxCount -= toRemove;

				if (copied[currentIndex] == 0) {
					timeLeft--;
					currentIndex++;
					nextIndex++;
				}
			}
		}

		return boxCount == 0;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		int pileCount = in.nextInt();
		long boxCount = 0;
		int studentCount = in.nextInt();
		int[] boxes = new int[pileCount];

		for (int i = 0; i < pileCount; i++) {
			boxes[i] = in.nextInt();
			boxCount += boxes[i];
		}

		int left = 0;
		int right = Integer.MAX_VALUE;

		while (left != right) {
			int middle = (left + right) / 2;
            // System.out.println(left + "/" + middle + "/" + right);

			if (valid(boxes, boxCount, studentCount, middle)) {
				right = middle;
			} else {
				left = middle + 1;
			}
		}

		System.out.println(left + 1);
	}

	public static boolean valid(int[] boxes, long boxCount, int studentCount, int time) {
		int[] copied = Arrays.copyOf(boxes, boxes.length);
		int nextIndex = 0;

		for (int i = 0; i < studentCount; i++) {
            int currentIndex = nextIndex;
			int timeLeft = time - currentIndex;

			while (timeLeft > 0 && currentIndex < copied.length) {
				int toRemove = Math.min(timeLeft, copied[currentIndex]);

				timeLeft -= toRemove;
				copied[currentIndex] -= toRemove;
				boxCount -= toRemove;

				if (copied[currentIndex] == 0) {
					timeLeft--;
					currentIndex++;
					nextIndex++;
				}
			}
		}

		return boxCount == 0;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		int pileCount = in.nextInt();
		long boxCount = 0;
		int studentCount = in.nextInt();
		int[] boxes = new int[pileCount];

		for (int i = 0; i < pileCount; i++) {
			boxes[i] = in.nextInt();
			boxCount += boxes[i];
		}

		int left = 0;
		int right = Integer.MAX_VALUE;

		while (left != right) {
			int middle = (left + right) / 2;
            System.out.println(left + "/" + middle + "/" + right);

			if (valid(boxes, boxCount, studentCount, middle)) {
				right = middle;
			} else {
				left = middle + 1;
			}
		}

		System.out.println(left + 1);
	}

	public static boolean valid(int[] boxes, long boxCount, int studentCount, int time) {
		int[] copied = Arrays.copyOf(boxes, boxes.length);
		int nextIndex = 0;

		for (int i = 0; i < studentCount; i++) {
            int currentIndex = nextIndex;
			int timeLeft = time - currentIndex;

			while (timeLeft > 0 && currentIndex < copied.length) {
				int toRemove = Math.min(timeLeft, copied[currentIndex]);

				timeLeft -= toRemove;
				copied[currentIndex] -= toRemove;
				boxCount -= toRemove;

				if (copied[currentIndex] == 0) {
					timeLeft--;
					currentIndex++;
					nextIndex++;
				}
			}
		}

		return boxCount == 0;
	}
}


import java.util.*;
import java.io.*;

public class C {
	FastScanner in;
	PrintWriter out;

	public void solve() throws IOException {
		int n = in.nextInt(), m = in.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextLong();
		}
		long tl = 0, tr = (long) 1e15;
		while (tr - tl > 1) {
			long tm = (tl + tr) / 2;
			boolean ok = true;
			int cm = m;
			long cv = 0;
			checkLoop:
			for (int i = n - 1; i >= 0; i--) {
				long ca = a[i];
				while (ca > 0) {
					while (cv <= 0 && cm > 0) {
						cv = tm - i - 1;
						cm--;
					}
					if (cv == 0 && cm == 0) {
						ok = false;
						break checkLoop;
					}
					long dm = Math.min(cv, ca);
					ca -= dm;
					cv -= dm;
				}
			}
			if (ok) {
				tr = tm;
			} else {
				tl = tm;
			}
		}
		out.println(tr);
	}

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] arg) {
		new C().run();
	}
}


import java.util.*;
import java.io.*;

public class A {
	FastScanner in;
	PrintWriter out;

	public void solve() throws IOException {
		int n = in.nextInt(), m = in.nextInt();
		long[] a = new long[n];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = in.nextLong();
			sum += a[i];
		}
		long tl = 0, tr = sum + n;
		while (tr - tl > 1) {
			long tm = (tl + tr) / 2;

			long[] b = new long[n];
			for (int i = 0; i < n; i++)
				b[i] = a[i];

			int p = n - 1;
			for (int i = 0; i < m; i++) {
				long cur = tm;
				while (p >= 0 && b[p] == 0)
					p--;
				if (cur < p + 1)
					break;
				cur -= (p + 1);
				while (p >= 0 && cur > 0) {
					long now = Math.min(cur, b[p]);
					b[p] -= now;
					cur -= now;
					if (b[p] == 0)
						p--;
				}
			}

			if (p < 0)
				tr = tm;
			else
				tl = tm;
		}
		out.println(tr);
	}

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] arg) {
		new A().run();
	}
}


import java.util.*;

public class C {
	static int[] bs;
	static int m;
	public static void main(String[] args) {

		Scanner qwe = new Scanner(System.in);

		int n = qwe.nextInt();
		m = qwe.nextInt();

		bs = new int[n];
		for (int i = 0; i < bs.length; i++) {
			bs[i] = qwe.nextInt();
		}

		long min = 0;
		long max = Long.MAX_VALUE/3;

		while(min +3 < max){

			long med = (min+max)/2;

			if(cando(med)){
				max = med;
			}
			else min = med;

		}

		for(int i = 0; i < 3; i++){
			if(cando(max-1)) max--;
		}

		System.out.println(max);

		qwe.close();
	}

	static boolean cando(long time){

		int sleft = m;

		int[] box = Arrays.copyOf(bs, bs.length);
		int i = 0;
		for(int loop = 0; loop < m; loop++){
			long ctime = time-(i+1);

			for(; i < box.length && ctime >= 0; i++){
				if(ctime >= box[i]){
					ctime -= box[i];
					box[i] = 0;
				}
				else{
					box[i] -= ctime;
					ctime = 0;
					break;
				}

				ctime--;

			}

		}

		for(i = 0; i < box.length; i++){
			if(box[i] != 0) return false;
		}

		return true;

	}

}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[]) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students; j++) {
            long currtime = time - i - 1;

            if (left != 0)
                currtime ++;
            if (currtime > left) {
                currtime -= left;
                left = 0;
            } else {
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && currtime > 0; i++) {
                if (data[i] != 0) {
                    if (data[i] <= currtime)
                        currtime -= data[i];
                    else {
                        left = data[i] - currtime;
                        currtime = 0;
                    }
                }
                currtime--;
            }
        }
        if (left != 0) return false;

        for (int t = i; t < data.length; i++)
            if (data[t] != 0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        for (int i = 0; i < n; i++)
            data[i] = in.nextInt();
        long lo = 0;
        long hi = Long.MAX_VALUE;
        long last = -1;
        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data);
            if (possible) {
                last = mid;
                hi = mid - 1;
            }
            else lo = mid + 1;
        }
        System.out.println(last);
//        System.out.println(calc(m, 3, data));
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[]) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students; j++) {
            long currtime = time - i;

            if (currtime > left) {
                currtime -= left;
                left = 0;
            } else {
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && currtime > 0; i++) {
                currtime--;
                if (data[i] <= currtime)
                    currtime -= data[i];
                else {
                    left = data[i] - currtime;
                    currtime = 0;
                }
            }
        }
        if (left != 0) return false;

        for (int t = i; t < data.length; i++)
            if (data[t] != 0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        for (int i = 0; i < n; i++)
            data[i] = in.nextInt();
        long lo = 0;
        long hi = Long.MAX_VALUE;
        long last = -1;
        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data);
            if (possible) {
                last = mid;
                hi = mid - 1;
            }
            else lo = mid + 1;
        }
        System.out.println(last);
//        System.out.println(calc(m, 3, data));
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[]) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students && (left != 0 || i < data.length); j++) {
            long currtime = time - i;

            if (currtime > left) {
                currtime -= left;
                left = 0;
            } else {
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && currtime > 0; i++) {
                currtime--;
                if (data[i] <= currtime)
                    currtime -= data[i];
                else {
                    left = data[i] - currtime;
                    currtime = 0;
                }
            }
        }
        if (left != 0) return false;

        for (int t = i; t < data.length; i++)
            if (data[t] != 0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        for (int i = 0; i < n; i++)
            data[i] = in.nextInt();
        long lo = 0;
        long hi = Long.MAX_VALUE;
        long last = -1;
        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data);
            if (possible) {
                last = mid;
                hi = mid - 1;
            }
            else lo = mid + 1;
        }
        System.out.println(last);
//        System.out.println(calc(m, 3, data));
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[]) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students; j++) {
            long currtime = time - i - 1;
            if (left != 0)
                currtime ++;
            if (currtime >= left) {
                currtime -= left;
                left = 0;
            } else {
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && currtime > 0; i++) {
                if (data[i] != 0) {
                    if (data[i] <= currtime)
                        currtime -= data[i];
                    else {
                        left = data[i] - currtime;
                        currtime = 0;
                    }
                }
                currtime--;
            }
        }
        if (left != 0) return false;

        for (int t = i; t < data.length; i++)
            if (data[t] != 0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        for (int i = 0; i < n; i++)
            data[i] = in.nextInt();
        long lo = 0;
        long hi = Long.MAX_VALUE;

        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data);
            if (possible) hi = mid - 1;
            else lo = mid + 1;
        }
        System.out.println(lo);
//        System.out.println(calc(m, 1, data));
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[]) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students; j++) {
            long currtime = time - i - 1;
            if (left != 0)
                currtime ++;
            if (currtime >= left) {
                currtime -= left;
                left = 0;
            } else {
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && currtime > 0; i++) {
                if (data[i] != 0) {
                    if (data[i] <= currtime)
                        currtime -= data[i];
                    else {
                        currtime = 0;
                        left = data[i] - currtime;
                    }
                }
                currtime--;
            }
        }
        if (left != 0) return false;

        for (int t = i; t < data.length; i++)
            if (data[t] != 0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        for (int i = 0; i < n; i++)
            data[i] = in.nextInt();
        long lo = 0;
        long hi = Long.MAX_VALUE;

        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data);
            if (possible) hi = mid - 1;
            else lo = mid + 1;
        }
        System.out.println(lo);
//        System.out.println(calc(m, 3, data));
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[], long sum) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students && sum > 0; j++) {
            long currtime = time - i;

            if (currtime > left) {
                sum -= left;
                currtime -= left;
                left = 0;
            } else {
                sum -= currtime;
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && sum > 0 && currtime > 0; i++) {
                currtime--;
                if (data[i] <= currtime) {
                    currtime -= data[i];
                    sum -= data[i];
                }
                else {
                    left = data[i] - currtime;
                    sum -= currtime;
                    currtime = 0;
                }
            }
        }
        return sum == 0;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            data[i] = in.nextInt();
            sum += data[i];
        }
        long lo = 0;
        long hi = Long.MAX_VALUE;
        long last = -1;
        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data, sum);
            if (possible) {
                last = mid;
                hi = mid - 1;
            }
            else lo = mid + 1;
        }
        System.out.println(last);
//        System.out.println(calc(m, 3, data));
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    public static boolean calc(int students, long time, int data[]) {
        int i = 0;
        long left = 0;
        for (int j = 0; j < students; j++) {
            long currtime = time - i - 1;

            if (left != 0)
                currtime ++;
            if (currtime >= left) {
                currtime -= left;
                left = 0;
            } else {
                left -= currtime;
                currtime = -1;
            }

            for (; i < data.length && currtime > 0; i++) {
                if (data[i] != 0) {
                    if (data[i] <= currtime)
                        currtime -= data[i];
                    else {
                        left = data[i] - currtime;
                        currtime = 0;
                    }
                }
                currtime--;
            }
        }
        if (left != 0) return false;

        for (int t = i; t < data.length; i++)
            if (data[t] != 0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int data[] = new int[n];
        for (int i = 0; i < n; i++)
            data[i] = in.nextInt();
        long lo = 0;
        long hi = Long.MAX_VALUE;
        long last = -1;
        while (lo <= hi) {
            long mid = lo + (hi - lo) / 2;
            boolean possible = calc(m, mid, data);
            if (possible) {
                last = mid;
                hi = mid - 1;
            }
            else lo = mid + 1;
        }
        System.out.println(last);
//        System.out.println(calc(m, 3, data));
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main3 {

	static FastReader input =new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static int n ;
	static int q ;
	static int []a;

	static boolean p(long m ) {

		long students = 0 ;
		long t = 0 ;

		for (int i= 0 ; i < n;i++) {

			long mod = a[i]%(m-i-1);
			long div = a[i]/(m-i-1) ;

			students+=div;

			if (t<mod) {
				mod-=t;
				students++;
				t = (m-i-1);
			}

			t-=mod;

			if (t==0&&i!=(n-1)) {
				students++;
				t = (m-i-1);
			}
			t--;
		}

		return students<=q ? true : false;

	}

	public static void main(String[] args) throws IOException {

		n = input.nextInt();
		q = input.nextInt();

		a = new int [n];

		for (int i = 0 ; i < n ; i++) {
			a[i] = input.nextInt();
		}

		long l =(long) n+1, r = Long.MAX_VALUE;

		while (r>l) {
			long m = l+(r-l)/2;
			if (p(m)) {
				r = m ;
			}
			else {
				l =  m+1;
			}
		}

		System.out.println(l);

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main3 {

	static FastReader input =new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static int n ;
	static int q ;
	static int []a;
	static int lastIndx ;

	static boolean p(long m ) {

		long students = 0 ;
		long t = 0 ;

		for (int i= 0 ; i < lastIndx+1;i++) {

			long mod = a[i]%(m-i-1);
			long div = a[i]/(m-i-1) ;

			students+=div;

			if (t<mod) {
				mod-=t;
				students++;
				t = (m-i-1);
			}

			t-=mod;

			if (t==0&&i!=(lastIndx)) {
				students++;
				t = (m-i-1);
			}
			t--;
		}

		return students<=q ? true : false;

	}

	public static void main(String[] args) throws IOException {

		n = input.nextInt();
		q = input.nextInt();

		a = new int [n];

		for (int i = 0 ; i < n ; i++) {
			a[i] = input.nextInt();
			if (a[i]!=0) lastIndx = i ;
		}

		long l =(long) lastIndx+2, r = Long.MAX_VALUE;
		while (r>l) {
			long m = l+(r-l)/2;
			if (p(m)) {
				r = m ;
			}
			else {
				l =  m+1;
			}
		}

		System.out.println(l);

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main3 {

	static FastReader input =new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static int n ;
	static int q ;
	static int []a;
	static int lastIndx ;

	static boolean p(long m ) {

		long students1 = 0 ;
		long students2 = 0 ;

		long t = 0 ;

		for (int i= lastIndx ; i>0; i--) {

			long x = m-i-1;

			long mod = a[i]%x;
			long div = a[i]/x;

			students2+=div;

			if (t<mod) {
				mod-=t;
				students2++;
				t = x;

			}

			t-=mod;

		}

		return students1<=q ? true : false;

	}

	public static void main(String[] args) throws IOException {

		n = input.nextInt();
		q = input.nextInt();

		a = new int [n];

		for (int i = 0 ; i < n ; i++) {
			a[i] = input.nextInt();
			if (a[i]!=0) lastIndx = i ;
		}

		long l =(long) lastIndx+2, r = Long.MAX_VALUE;

		while (r>l) {
			long m = l+(r-l)/2;

			if (p(m)) {
				r = m ;
			}

			else {
				l =  m+1;
			}

		}

		System.out.println(l);

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main3 {

	static FastReader input =new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static int n ;
	static int q ;
	static int []a;
	static int lastIndx ;

	static boolean p(long m ) {

		long t = 0 ;
		long students2 = 0 ;

		for (int i= lastIndx ; i>=0; i--) {

			long x = m-i-1;

			long mod = a[i]%x;
			long div = a[i]/x;

			students2+=div;

			if (t<mod) {
				mod-=t;
				students2++;
				t = x;

			}

			t-=mod;

		}

		return students2<=q ? true : false;

	}

	public static void main(String[] args) throws IOException {

		n = input.nextInt();
		q = input.nextInt();

		a = new int [n];

		for (int i = 0 ; i < n ; i++) {
			a[i] = input.nextInt();
			if (a[i]!=0) lastIndx = i ;
		}

		long l =(long) lastIndx+2, r = Long.MAX_VALUE;

		while (r>l) {
			long m = l+(r-l)/2;

			if (p(m)) {
				r = m ;
			}

			else {
				l =  m+1;
			}

		}

		System.out.println(l);

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}
}


//package practice;
/**
 * Created by Rajan Waliya on 25-Aug-15.
 */

import java.io.*;
import java.util.*;

//public
class C551 {

    Reader sc;
    PrintWriter out;

    void solve() throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n+1];
        long sum = 0;
        for(int i=0;i<n;i++){
            a[i+1]=sc.nextInt();
            sum+=a[i+1];
        }
        int[] b;
        long time = 0;

        //binary search for ans
        long l=0;
        long r=sum+n;
        while(l<r){
            long mid = (l+r)/2;
            int p = 0;
            b = a.clone();
            for(int i=0;i<m;i++) {
                while (p <=n && b[p] == 0) {p++;}  //take index of last non-zero pile
                long t = mid - p;//time taken to reach here
                if (t <= 0) {break;}
                while (p <=n && b[p] <= t) {t -= b[p++];} // decrease time and move to next{no need to make zero}
                if(p<=n){b[p]-=t;}//if was more than time left then take as many as can, not all though
            }
            if(p>n){r=mid;}
            else{l=mid+1;}
        }

        System.out.println(r);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new C551().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 25-Aug-15.
 */

import java.io.*;
import java.util.*;

//public
class C551 {

    Reader sc;
    PrintWriter out;

    void solve() throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n+1];
        long sum = 0;
        for(int i=0;i<n;i++){
            a[i+1]=sc.nextInt();
            sum+=a[i+1];
        }
        int[] b;

        //binary search for ans
        long l=0;
        long r=sum+n;
        while(l<r){
            long mid = (l+r)/2;
            int p = 0;
            b = a.clone();
            for(int i=0;i<m;i++) {
                while (p <=n && b[p] == 0) {p++;}  //take index of last non-zero pile
                long t = mid - p;//time taken to reach here
                if (t <= 0) {break;}
                while (p <=n && b[p] <= t) {t -= b[p++];if(p<n){t--;}} // decrease time and move to next{no need to make zero}
                if(p<=n){b[p]-=t;}//if was more than time left then take as many as can, not all though
            }
            if(p>n){r=mid;}
            else{l=mid+1;}
        }

        System.out.println(r);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new C551().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


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;
        }
        System.out.println(r);
    }
}/


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;
        }
        System.out.println(r);
    }
}


//package practice;
/**
 * Created by Rajan Waliya on 25-Aug-15.
 */

import java.io.*;
import java.util.*;

//public
class C551 {

    Reader sc;
    PrintWriter out;

    void solve() throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n+1];
        long sum = 0;
        for(int i=0;i<n;i++){
            a[i+1]=sc.nextInt();
            sum+=a[i+1];
        }
        int[] b;
        long time = 0;

        //binary search for ans
        long l=0;
        long r=sum+n;
        while(l<r){
            long mid = (l+r)/2;
            int p = n;
            b = a.clone();
            for(int i=0;i<m;i++) {
                while (p > 0 && b[p] == 0) {p--;}  //take index of last non-zero pile
                long t = mid - p;//time taken to reach here
                if (t <= 0) {break;}
                while (p > 0 && b[p] <= t) {t -= b[p--];} // decrease time and move to next{no need to make zero}
                if(p>0){b[p]-=t;}//if was more than time left then take as many as can, not all though
            }
            if(p<=0){r=mid;}
            else{l=mid+1;}
        }

        System.out.println(r);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new C551().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


//package practice;
/**
 * Created by Rajan Waliya on 25-Aug-15.
 */

import java.io.*;
import java.util.*;

//public
class C551 {

    Reader sc;
    PrintWriter out;

    void solve() throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n+1];
        long sum = 0;
        for(int i=0;i<n;i++){
            a[i+1]=sc.nextInt();
            sum+=a[i+1];
        }
        int[] b;
        long time = 0;

        //binary search for ans
        long l=0;
        long r=sum+n;
        while(l<r){
            long mid = (l+r)/2;
            int p = n;
            b = a.clone();
            for(int i=0;i<m;i++) {
                while (p <=n && b[p] == 0) {p++;}  //take index of last non-zero pile
                long t = mid - p;//time taken to reach here
                if (t <= 0) {break;}
                while (p <=n && b[p] <= t) {t -= b[p++];} // decrease time and move to next{no need to make zero}
                if(p<=n){b[p]-=t;}//if was more than time left then take as many as can, not all though
            }
            if(p>n){r=mid;}
            else{l=mid+1;}
        }

        System.out.println(r);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new C551().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


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;
        }
        System.out.println(r);
    }
}


//package practice;
/**
 * Created by Rajan Waliya on 25-Aug-15.
 */

import java.io.*;
import java.util.*;

//public
class C551 {

    Reader sc;
    PrintWriter out;

    void solve() throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n+1];
        long sum = 0;
        for(int i=0;i<n;i++){
            a[i+1]=sc.nextInt();
            sum+=a[i+1];
        }
        int[] b;

        //binary search for ans
        long l=0;
        long r=sum+n;
        while(l<r){
            long mid = (l+r)/2;
            int p = 0;
            b = a.clone();
            for(int i=0;i<m;i++) {
                while (p <=n && b[p] == 0) {p++;}  //take index of last non-zero pile
                long t = mid - p;//time taken to reach here
                if (t <= 0) {break;}
                while (p <=n && b[p] <= t) {t -= b[p++];t--;} // decrease time and move to next{no need to make zero}
                if(p<=n){b[p]-=t;}//if was more than time left then take as many as can, not all though
            }
           // System.out.println("for mid="+mid+" p is "+p);
            if(p>n){r=mid;}
            else{l=mid+1;}
        }

        System.out.println(r);
    }

    //_______congratulation!!! main logic has ended, no need to understand what is after this line.________
    void runIO() throws Exception {
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new C551().runIO();
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10L + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            byte c;
            while ((c = read()) <= ' ') ;
            do {
                sb.append((char) c);
            } while ((c = read()) > ' ');
            return sb.toString();
        }

        public int nextInt2() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class zizo5{
	public static void main (String[] args) throws InterruptedException, IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt(), m = sc.nextInt();
		ArrayList<Pair> f_boxes = new ArrayList<Pair>(n);
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if(a != 0)
				f_boxes.add(new Pair(a, i));
		}
		out.println(BS(f_boxes, m));

		out.flush();
		out.close();
	}

	public static long BS(ArrayList<Pair> al, int m) {
		long low = al.get(al.size()-1).idx+2, high = (long)(1e14 + 1e5), ans = 0;
		while(low <= high) {
			long mid = low + high >> 1;
			ArrayList<Pair> p = new ArrayList<Pair>(al.size());
			p.addAll(al);
			if(can(p, m, mid)) {
				ans = mid;
				high = mid-1;
			}
			else
				low = mid+1;
		}
		return ans;
	}

	public static boolean can(ArrayList<Pair> al, int m, long t) {
		boolean ans = false;
		for(int i = 0, j = 0; i < m; i++) {
			long cur_t = t;
			boolean first = true;
			while(j < al.size() && cur_t > 0) {
				Pair a = al.get(j);
				cur_t = cur_t - (first?a.idx+1:a.idx-al.get(j-1).idx);
				if(cur_t <= 0)
					break;
				if(cur_t >= a.v) {
					cur_t-=a.v;
					j++;
					if(j == al.size()) {
						ans = true;
						break;
					}
					first = false;
				}
				else {
					al.get(j).v-=cur_t;
					cur_t = 0;
				}
			}
			if(ans)
				break;
		}
		return ans;
	}

	static class Pair{
		int v, idx;

		public Pair(int a, int b) {
			v = a;
			idx = b;
		}
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException{return Double.parseDouble(next());}

		public boolean ready() throws IOException {return br.ready();}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class zizo5{
	public static void main (String[] args) throws InterruptedException, IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt(), m = sc.nextInt();
		ArrayList<Pair> f_boxes = new ArrayList<Pair>(n);
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if(a != 0)
				f_boxes.add(new Pair(a, i));
		}
		out.println(BS(f_boxes, m));
	//	out.println("4 "+can(f_boxes, m, 4));

		out.flush();
		out.close();
	}

	public static long BS(ArrayList<Pair> al, int m) {
		long low = al.get(al.size()-1).idx+2, high = (long)(1e14 + 1e5), ans = 0;
		while(low <= high) {
			long mid = low + high >> 1;
			ArrayList<Pair> p = new ArrayList<Pair>(al.size());
			for(int i = 0; i < al.size(); i++)
				p.add(new Pair(al.get(i).v, al.get(i).idx));
			//System.out.println(p);
			//System.out.println(mid + " "+ can(p, m, mid));
			if(can(p, m, mid)) {
				ans = mid;
				high = mid-1;
			}
			else
				low = mid+1;
		}
		return ans;
	}

	public static boolean can(ArrayList<Pair> p, int m, long t) {
		boolean ans = false;
		for(int i = 0, j = 0; i < m; i++) {
			long cur_t = t;
			boolean first = true;
			while(j < p.size() && cur_t > 0) {
				Pair a = p.get(j);
				cur_t = cur_t - (first?a.idx+1:a.idx-p.get(j-1).idx);
				//System.out.println(cur_t);
				if(cur_t <= 0)
					break;
				if(cur_t >= a.v) {
					cur_t-=a.v;
					//System.out.println(cur_t);
					j++;
					if(j == p.size()) {
						ans = true;
						break;
					}
					first = false;
				}
				else {
					p.get(j).v-=cur_t;
					cur_t = 0;
					//System.out.println(cur_t);
				}
			}
			if(ans)
				break;
		}
		return ans;
	}

	static class Pair{
		int v, idx;

		public Pair(int a, int b) {
			v = a;
			idx = b;
		}
		public String toString() {
			return v+"";
		}
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException{return Double.parseDouble(next());}

		public boolean ready() throws IOException {return br.ready();}

	}

}