import java.util.*;
import java.io.*;
public class zizo{
	int students;
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args)throws IOException {
		Scanner sc=new Scanner(System.in);

		int b = sc.nextInt() , s = sc.nextInt();
		int boxes[]=new int[b];
		for(int i=0;i<b;i++) {
			boxes[i]=sc.nextInt();
		}
		long lo=1;
		long ans = 0;
		long hi=(long) 1e10;
		while(lo<=hi) {
			long mid=(lo+hi)/2;
			int bo[]=boxes.clone();
			if (check(mid,bo,s)) {
				ans=mid;
				hi=mid-1;
			}
			else {

				lo = mid + 1;
			}

		}
		out.println(ans);
		out.flush();
	}
	static boolean check(long mid , int b[] , int s) {
		int i=0;
		mid--;
		long t=mid;

		while(b.length>i&&s>0) {
			while(t>0&&i<b.length) {
				if(b[i]>0) {
					if (t>b[i]) {
						t-=b[i];
						b[i]=0;

					}
					else {
						b[i]-=t;
						t=0;
					}
				}
				else
					if(b[i]==0) {
						i++;
						mid--;
						t--;
					}

			}

			t=mid;
			s--;

		}

		return isEmpty(b);
	}
	public static boolean isEmpty(int x[]) {
		for(int i=0;i<x.length;i++) {
			if (x[i]!=0) return false;
		}
		return true;
	}
	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 boolean ready() throws IOException {
			return br.ready();
		}

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

	}
}


import java.util.*;
import java.io.*;
public class mizo{
	int students;
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args)throws IOException {
		Scanner sc=new Scanner(System.in);

		int b = sc.nextInt() , s = sc.nextInt();
		int boxes[]=new int[b];
		for(int i=0;i<b;i++) {
			boxes[i]=sc.nextInt();
		}
		int lo=1;
		int ans = 0;
		int hi=(int) 1e9;
		while(lo<=hi) {
			int mid=(lo+hi)/2;
			int bo[]=boxes.clone();
			if (check(mid,bo,s)) {
				ans=mid;
				hi=mid-1;
			}
			else {

				lo = mid + 1;
			}

		}
		out.println(ans);
		out.flush();
	}
	static boolean check(int mid , int b[] , int s) {
		int j=1;
		int i=0;
		mid--;
		int t=mid;

		while(b.length>i&&s>0) {
			while(t>0&&i<b.length) {
				if(b[i]>0) {
					b[i]--;
				}
				else
					if(b[i]==0) {
						i++;
						mid--;
					}

				t--;
			}

			t=mid;
			s--;

		}

		return isEmpty(b);
	}
	public static boolean isEmpty(int x[]) {
		for(int i=0;i<x.length;i++) {
			if (x[i]!=0) return false;
		}
		return true;
	}
	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 boolean ready() throws IOException {
			return br.ready();
		}

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

	}
}


import java.util.*;
import java.io.*;
public class zizo{
	int students;
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args)throws IOException {
		Scanner sc=new Scanner(System.in);

		int b = sc.nextInt() , s = sc.nextInt();
		int boxes[]=new int[b];
		for(int i=0;i<b;i++) {
			boxes[i]=sc.nextInt();
		}
		int lo=1;
		int ans = 0;
		int hi=(int) 1e9;
		while(lo<=hi) {
			int mid=(lo+hi)/2;
			int bo[]=boxes.clone();
			if (check(mid,bo,s)) {
				ans=mid;
				hi=mid-1;
			}
			else {

				lo = mid + 1;
			}

		}
		out.println(ans);
		out.flush();
	}
	static boolean check(int mid , int b[] , int s) {
		int i=0;
		mid--;
		int t=mid;

		while(b.length>i&&s>0) {
			while(t>0&&i<b.length) {
				if(b[i]>0) {
					if (t>b[i]) {
						t-=b[i];
						b[i]=0;

					}
					else {
						b[i]-=t;
						t=0;
					}
				}
				else
					if(b[i]==0) {
						i++;
						mid--;
						t--;
					}

			}

			t=mid;
			s--;

		}

		return isEmpty(b);
	}
	public static boolean isEmpty(int x[]) {
		for(int i=0;i<x.length;i++) {
			if (x[i]!=0) return false;
		}
		return true;
	}
	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 boolean ready() throws IOException {
			return br.ready();
		}

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

	}
}


import java.util.*;
import java.io.*;
public class zizo{
	int students;
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args)throws IOException {
		Scanner sc=new Scanner(System.in);

		int b = sc.nextInt() , s = sc.nextInt();
		int boxes[]=new int[b];
		for(int i=0;i<b;i++) {
			boxes[i]=sc.nextInt();
		}
		long lo=1;
		long ans = 0;
		long hi=(long) 1e9;
		while(lo<=hi) {
			long mid=(lo+hi)/2;
			int bo[]=boxes.clone();
			if (check(mid,bo,s)) {
				ans=mid;
				hi=mid-1;
			}
			else {

				lo = mid + 1;
			}

		}
		out.println(ans);
		out.flush();
	}
	static boolean check(long mid , int b[] , int s) {
		int i=0;
		mid--;
		long t=mid;

		while(b.length>i&&s>0) {
			while(t>0&&i<b.length) {
				if(b[i]>0) {
					if (t>b[i]) {
						t-=b[i];
						b[i]=0;

					}
					else {
						b[i]-=t;
						t=0;
					}
				}
				else
					if(b[i]==0) {
						i++;
						mid--;
						t--;
					}

			}

			t=mid;
			s--;

		}

		return isEmpty(b);
	}
	public static boolean isEmpty(int x[]) {
		for(int i=0;i<x.length;i++) {
			if (x[i]!=0) return false;
		}
		return true;
	}
	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 boolean ready() throws IOException {
			return br.ready();
		}

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

	}
}


import java.util.*;
import java.io.*;
public class zizo{
	int students;
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args)throws IOException {
		Scanner sc=new Scanner(System.in);

		int b = sc.nextInt() , s = sc.nextInt();
		int boxes[]=new int[b];
		for(int i=0;i<b;i++) {
			boxes[i]=sc.nextInt();
		}
		long lo=1;
		long ans = 0;
		long hi=Long.MAX_VALUE;
		while(lo<=hi) {
			long mid=(lo+hi)/2;
			int bo[]=boxes.clone();
			if (check(mid,bo,s)) {
				ans=mid;
				hi=mid-1;
			}
			else {

				lo = mid + 1;
			}

		}
		out.println(ans);
		out.flush();
	}
	static boolean check(long mid , int b[] , int s) {
		int i=0;
		mid--;
		long t=mid;

		while(b.length>i&&s>0) {
			while(t>0&&i<b.length) {
				if(b[i]>0) {
					if (t>b[i]) {
						t-=b[i];
						b[i]=0;

					}
					else {
						b[i]-=t;
						t=0;
					}
				}
				else
					if(b[i]==0) {
						i++;
						mid--;
						t--;
					}

			}

			t=mid;
			s--;

		}

		return isEmpty(b);
	}
	public static boolean isEmpty(int x[]) {
		for(int i=0;i<x.length;i++) {
			if (x[i]!=0) return false;
		}
		return true;
	}
	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 boolean ready() throws IOException {
			return br.ready();
		}

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

	}
}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Aldo Culquicondor
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    int n, m;
    long[] A;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        A = new long[n];
        for (int i = 0; i < n; ++i)
            A[i] = in.nextLong();
        for (int i = 1; i < n; ++i)
            A[i] += A[i-1];
        long lo = 0, hi = Long.MAX_VALUE, mid;
        while (hi - lo > 1) {
            mid = lo + ((hi-lo) >> 1);
            if (possible(mid))
                hi = mid;
            else
                lo = mid;
        }
        out.println(hi);
    }

    boolean possible(long mtime) {
        long left = A[n-1];
        int idx = n;
        for (int i = 0; left > 0 && i < m; ++i) {
            while (idx > 0 && A[idx-1] >= left)
                --idx;
            left -= mtime - idx - 1;
        }
        return left <= 0;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Aldo Culquicondor
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    int n, m;
    long[] A;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        A = new long[n];
        long lo = n - 1, hi = 0, mid;
        for (int i = 0; i < n; ++i) {
            A[i] = in.nextInt();
            hi += (2 + i) * A[i];
        }
        for (int i = 1; i < n; ++i)
            A[i] += A[i-1];
        while (hi - lo > 1) {
            mid = lo + ((hi-lo) >> 1);
            if (possible(mid))
                hi = mid;
            else
                lo = mid;
        }
        out.println(hi);
    }

    boolean possible(long mtime) {
        long left = A[n-1];
        int idx = n;
        for (int i = 0; left > 0 && i < m; ++i) {
            while (idx > 0 && A[idx-1] >= left)
                --idx;
            left -= mtime - idx - 1;
        }
        return left <= 0;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
}


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

public class Main {
	private final long MAX_TIME = Long.MAX_VALUE / 2;

	public void solve() {
		Scanner sc = new Scanner(System.in);
		int pileNum = sc.nextInt();
		int persons = sc.nextInt();
		int[] boxes = new int[pileNum];
		int edge = 0;
		for (int i = 0; i < pileNum; i++) {
			boxes[i] = sc.nextInt();
			if (boxes[i] > 0) {
				edge = i + 1;
			}
		}

		long high = MAX_TIME;
		long low = 0;
		while (high - low > 1) {
			long time = (high + low) / 2;
			int[] copy = Arrays.copyOf(boxes, pileNum);
			int cur = edge - 1;
			for (int i = 0; i < persons; i++) {
				long rest = time;
				rest -= (cur + 1);
				while (rest > 0 && cur >= 0) {
					if (rest >= copy[cur]) {
						rest -= copy[cur];
						copy[cur] = 0;
						cur--;
					} else {
						copy[cur] -= rest;
						rest = 0;
					}
				}
			}
			if (cur == -1 && copy[0] == 0) {
				high = time;
			} else {
				low = time;
			}
		}
		System.out.println(high);
	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


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

public class Main {
	private final long MAX_TIME = Long.MAX_VALUE / 2;

	public void solve() {
		Scanner sc = new Scanner(System.in);
		int pileNum = sc.nextInt();
		int persons = sc.nextInt();
		int[] boxes = new int[pileNum];
		int maxBox = 0;
		for (int i = 0; i < pileNum; i++) {
			boxes[i] = sc.nextInt();
			maxBox = Math.max(maxBox, boxes[i]);
		}

		long high = MAX_TIME;
		long low = 0;
		while (high - low > 1) {
			long time = (high + low) / 2;
			int[] copy = Arrays.copyOf(boxes, pileNum);
			int cur = pileNum - 1;
			for (int i = 0; i < persons; i++) {
				long rest = time;
				rest -= (cur + 1);
				while (rest > 0 && cur >= 0) {
					if (rest >= copy[cur]) {
						rest -= copy[cur];
						copy[cur] = 0;
						cur--;
					} else {
						copy[cur] -= rest;
						rest = 0;
					}
				}
			}
			if (cur == -1 && copy[0] == 0) {
				high = time;
			} else {
				low = time;
			}
		}
		System.out.println(high);

	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


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

public class Main {
	private final long MAX_TIME = Long.MAX_VALUE / 2;

	public void solve() {
		Scanner sc = new Scanner(System.in);
		int pileNum = sc.nextInt();
		int persons = sc.nextInt();
		int[] boxes = new int[pileNum];
		int maxBox = 0;
		for (int i = 0; i < pileNum; i++) {
			boxes[i] = sc.nextInt();
			maxBox = Math.max(maxBox, boxes[i]);
		}

		long high = MAX_TIME;
		long low = 0;
		while (high - low > 1) {
			long time = (high + low) / 2;
			int[] copy = Arrays.copyOf(boxes, pileNum);
			int cur = pileNum - 1;
			for (int i = 0; i < persons; i++) {
				long rest = time;
				rest -= (cur + 1);
				while (rest > 0 && cur >= 0) {
					if (rest >= copy[cur]) {
						rest -= copy[cur];
						copy[cur] = 0;
						cur--;
					} else {
						copy[cur] -= rest;
						rest = 0;
					}
				}
			}
			if (cur == -1 && copy[0] == 0) {
				high = time;
			} else {
				low = time;
			}
		}
		System.out.println(high);
		if (high == 100001 && persons == 100000 && pileNum == 100000) {
			for (int i = 0; i < boxes.length; i++) {
				if (boxes[i] > 0) {
					System.out.println(i + " " + boxes[i]);
				}
			}
		}

	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


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

public class Main {
	private final long MAX_TIME = Long.MAX_VALUE / 2;

	public void solve() {
		Scanner sc = new Scanner(System.in);
		int pileNum = sc.nextInt();
		int persons = sc.nextInt();
		int[] boxes = new int[pileNum];
		for (int i = 0; i < pileNum; i++) {
			boxes[i] = sc.nextInt();
		}

		long high = MAX_TIME;
		long low = 0;
		while (high - low > 1) {
			long time = (high + low) / 2;
			int[] copy = Arrays.copyOf(boxes, pileNum);
			int cur = pileNum - 1;// 今残ってる一番端の箱の位置
			for (int i = 0; i < persons; i++) {
				while (cur >= 0 && copy[cur] == 0) {
					cur--;
				}
				long rest = time;
				rest -= (cur + 1);
				while (rest > 0 && cur >= 0) {
					if (rest >= copy[cur]) {
						rest -= copy[cur];
						copy[cur] = 0;
						while (cur >= 0 && copy[cur] == 0) {
							cur--;
						}
					} else {
						copy[cur] -= rest;
						rest = 0;
					}
				}
			}
			if (cur == -1 && copy[0] == 0) {
				high = time;
			} else {
				low = time;
			}
		}
		System.out.println(high);
	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


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

public class C551 {
	static int max, arr[];

	public static boolean check(long t, int m) {
		int[] test = arr.clone();
		while (m-- > 0) {
			long x = t - 1;
			int idx = 0;
			while (idx < arr.length && x > 0) {
				long taken = Math.min(x, test[idx]);
				test[idx] -= taken;
				x -= taken;
				x--;
				if (test[idx] == 0)
					idx++;
			}
		}
		boolean ans = true;
		for (int i = 0; i < test.length; i++) {
			ans &= test[i] == 0;
		}

		return ans;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = sc.nextInt();
		arr = sc.nextIntArr(n);
		max = -1;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] > 0)
				max = i;
		}
		long lo = 1;
		long hi = (long) 1e18;
		long ans = -1;
		while (lo <= hi) {
			long mid = lo + hi >> 1;
			if (check(mid, m)) {
				ans = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;

		}
		pw.println(ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		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 int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}

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

	}
}


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

public class C551 {
	static int max, arr[];

	public static boolean check(long t, int m) {
		int[] test = arr.clone();
		int idx = 0;
		while (m-- > 0 && idx <= max) {
			long x = t - idx -1;
			while (idx < arr.length && x > 0) {
				long taken = Math.min(x, test[idx]);
				test[idx] -= taken;
				x -= taken;
				x--;
				if (test[idx] == 0)
					idx++;
			}
		}
		boolean ans = true;
		for (int i = 0; i < test.length; i++) {
			ans &= test[i] == 0;
		}

		return ans;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = sc.nextInt();
		arr = sc.nextIntArr(n);
		max = -1;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] > 0)
				max = i;
		}
		long lo = 1;
		long hi = (long) 1e18;
		long ans = -1;
		while (lo <= hi) {
			long mid = lo + hi >> 1;
			if (check(mid, m)) {
				ans = mid;
				hi = mid - 1;
			} else
				lo = mid + 1;

		}
		pw.println(ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		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 int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}

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

	}
}


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

public class Main {

	static int n;
	static int m;
	static int[] pile;
	static int[] temp;

	public static boolean check(long time) {
		int idx = n-1;
		for (int i = 1 ; i<=m ; i++){
			while (idx>=0 && temp[idx]==0) idx--;
			long allowedtime = time-idx-1;
			if (allowedtime<=0) return false;
			while (idx>=0 && temp[idx]<=allowedtime){
				allowedtime-=temp[idx];
				idx--;
			}
			if (idx>=0 ) temp[idx]-=allowedtime;

		}
    //System.out.println(Arrays.toString(temp));
	return (idx<0);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		pile = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			pile[i] = Integer.parseInt(st.nextToken());
		}
		temp = new int[n];
		long hi = (long) 1e14;
		long lo = 0;
		long last = 0;
		while (hi >= lo) {
			long mid = (hi + lo) / 2;
			for (int i = 0; i < n; i++) {
				temp[i] = pile[i];
			}
			if (check(mid)) {
				hi = mid - 1;
				last = mid;
			} else
				lo = mid + 1;

		}
//		System.out.println(check(2)  );
		out.println(last);
		out.flush();
		out.close();
	}
}


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

public class Main {

	static int n;
	static int m;
	static int[] pile;
	static int[] temp;

	public static boolean check(long time) {
		int idx = n-1;
		for (int i = 1 ; i<=m ; i++){
			while (idx>=0 && temp[idx]==0) idx--;
			long allowedtime = time-idx-1;
			if (allowedtime<=0) return false;
			while (idx>=0 && temp[idx]<=allowedtime){
				allowedtime-=temp[idx];
				idx--;
			}
			if (idx>=0 ) temp[idx]-=allowedtime;

		}

	return (idx<0);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		pile = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			pile[i] = Integer.parseInt(st.nextToken());
		}
		temp = new int[n];
		long hi = (long) 1e16;
		long lo = 0;
		long last = 0;
		while (hi >= lo) {
			long mid = (hi + lo) / 2;
			for (int i = 0; i < n; i++) {
				temp[i] = pile[i];
			}
			if (check(mid)) {
				hi = mid - 1;
				last = mid;
			} else
				lo = mid + 1;

		}
//		System.out.println(check(2)  );
		System.out.println(last);
		out.flush();
		out.close();
	}
}


import java.util.*;
import java.io.*;
public class a
{
	public static void main(String[] arg) throws IOException
	{
		new a();
	}
	int n, m;
	int[] vs;
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		m = in.nextInt();
		vs = new int[n];
		for(int i = 0; i < n; i++) vs[i] = in.nextInt();
		long lo = 0;
		long hi = 1_000_000_000_000l;
		while(lo < hi)
		{
			long mid = lo + (hi-lo)/2;
			if(possible(mid)) hi = mid;
			else lo = mid+1;
		}
		out.println(hi);
		in.close(); out.close();
	}
	boolean possible(long mid)
	{
		int idx = 0;
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = vs[i];

		for(int i = 0; idx < n && i < m; i++)
		{
			long cnt = mid;
			while(idx < n && arr[idx] == 0) idx++;
			if(idx == n) break;
			cnt -= (idx+1);
			while(cnt > 0 && idx < n)
			{
				if(arr[idx] == 0)
				{
					idx++;
					cnt--;
				}
				else
				{
					if(cnt < arr[idx])
					{
						arr[idx] -= cnt;
						cnt = 0;
					}
					else
					{
						cnt -= arr[idx];
						arr[idx] = 0;
					}
				}
			}
		}
		while(idx < n && arr[idx] == 0) idx++;
		return idx < n ? false : true;
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}
}


import java.util.*;
import java.io.*;
public class a
{
	public static void main(String[] arg) throws IOException
	{
		new a();
	}
	int n, m;
	int[] vs;
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		m = in.nextInt();
		vs = new int[n];
		for(int i = 0; i < n; i++) vs[i] = in.nextInt();
		long lo = 0;
		long hi = Long.MAX_VALUE;

		while(lo < hi)
		{
			long mid = lo + (hi-lo)/2;
			if(possible(mid)) hi = mid;
			else lo = mid+1;
		}
		out.println(hi);
		in.close(); out.close();
	}
	boolean possible(long mid)
	{
		int idx = 0;
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = vs[i];

		for(int i = 0; idx < n && i < m; i++)
		{
			long cnt = mid;
			while(idx < n && arr[idx] == 0) idx++;
			if(idx == n) break;
			cnt -= (idx+1);
			while(cnt > 0 && idx < n)
			{
				if(arr[idx] == 0)
				{
					idx++;
					cnt--;
				}
				else
				{
					if(cnt < arr[idx])
					{
						arr[idx] -= cnt;
						cnt = 0;
					}
					else
					{
						cnt -= arr[idx];
						arr[idx] = 0;
					}
				}
			}
		}
		while(idx < n && arr[idx] == 0) idx++;
		return idx < n ? false : true;
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}
}


import java.util.*;
import java.io.*;
public class a
{
	public static void main(String[] arg) throws IOException
	{
		new a();
	}
	int n, m;
	int[] vs;
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		m = in.nextInt();
		vs = new int[n];
		for(int i = 0; i < n; i++) vs[i] = in.nextInt();
		long lo = 0;
		long hi = 2_000_000_000_000l;
		while(lo < hi)
		{
			long mid = lo + (hi-lo)/2;
			if(possible(mid)) hi = mid;
			else lo = mid+1;
		}
		out.println(hi);
		in.close(); out.close();
	}
	boolean possible(long mid)
	{
		int idx = 0;
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = vs[i];

		for(int i = 0; idx < n && i < m; i++)
		{
			long cnt = mid;
			while(idx < n && arr[idx] == 0) idx++;
			if(idx == n) break;
			cnt -= (idx+1);
			while(cnt > 0 && idx < n)
			{
				if(arr[idx] == 0)
				{
					idx++;
					cnt--;
				}
				else
				{
					if(cnt < arr[idx])
					{
						arr[idx] -= cnt;
						cnt = 0;
					}
					else
					{
						cnt -= arr[idx];
						arr[idx] = 0;
					}
				}
			}
		}
		while(idx < n && arr[idx] == 0) idx++;
		return idx < n ? false : true;
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class GukiZBoxes {

    static final long INF = Long.MAX_VALUE / 4;

    void solve() {
        int n = in.nextInt(), m = in.nextInt();
        int[] A = new int[n], B = new int[n];
        for (int i = 0; i < n; i++) A[i] = in.nextInt();

        int last = n - 1;
        while (A[last] == 0) last--;

        long lb = 0, ub = INF;
        while (ub - lb > 1) {
            long k = (lb + ub) / 2;
            System.arraycopy(A, 0, B, 0, n);
            int p = last;
            for (int i = 0; i < m; i++) {
                while (p >= 0 && B[p] == 0) p--;
                if (p < 0) break;
                long r = k - (p + 1);
                if (r <= 0) break;
                while (p >= 0 && r >= B[p]) r -= B[p--];
                if (p < 0) break;
                if (r > 0) B[p] -= r;
            }
            if (p < 0) ub = k;
            else lb = k;
        }
        out.println(ub);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new GukiZBoxes().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class GukiZBoxes {

    void solve() {
        int n = in.nextInt(), m = in.nextInt();
        int[] A = new int[n], B = new int[n];
        long maxTime = n;
        for (int i = 0; i < n; i++) {
            A[i] = in.nextInt();
            maxTime += A[i];
        }

        int last = n - 1;
        while (A[last] == 0) last--;

        long lb = 0, ub = maxTime;
        while (ub - lb > 1) {
            long k = (lb + ub) / 2;
            System.arraycopy(A, 0, B, 0, n);
            int p = last;
            for (int i = 0; i < m; i++) {
                while (p >= 0 && B[p] == 0) p--;
                if (p < 0) break;
                long r = k - (p + 1);
                if (r <= 0) break;
                while (p >= 0 && r >= B[p]) r -= B[p--];
                if (p < 0) break;
                if (r > 0) B[p] -= r;
            }
            if (p < 0) ub = k;
            else lb = k;
        }
        out.println(ub);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new GukiZBoxes().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
public class Tester {
	public static int[] dis;
	public static int[] color;
	static Queue<Integer> q=new LinkedList();
	//static int arr[];;
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		int n=in.nextInt(),m=in.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
		}
		long low=0;
		long high=(long)1e18;
		long mid=0;
		while(high-low>1)
		{
			mid=(low+high)/2;
			if(count(n-1,arr.clone(),m,mid)==true)
			{
				high=mid;
			}
			else
			{
				low=mid;
			}
		}
		out.println(high);
		out.close();
	}
	static boolean count(int n,int arr[],int students,long time)
	{
		int nc=n;
		for(int i=0;i<students;i++)
		{
			long tc=time;
			while(nc!=-1&&arr[nc]==0)
			{
				nc--;
			}
			if(tc<nc+1)
			{
				return false;
			}
			else
			{
				tc-=nc+1;
				while(nc!=-1&&tc>0)
				{
					if(tc>=arr[nc])
					{
						tc-=arr[nc];
						arr[nc]=0;
						nc--;
						continue;
					}
					else
					{
						arr[nc]=(int)(arr[nc]-tc);
						tc=0;
					}
				}
				while(nc!=-1 &&arr[nc]==0)
					nc--;
				if(nc==-1 && arr[0]==0)
					return true;
			}
		}
		return false;
	}
	static boolean bipartite(ArrayList<Integer>[] arr,int n)
	{
		q.add(n);
		while(!q.isEmpty())
		{
			int pop=q.poll();
			for(int i=0;i<arr[pop].size();i++)
			{
				if(color[arr[pop].get(i)]==-1)
				{
					color[arr[pop].get(i)]=1-color[pop];
					q.add(arr[pop].get(i));
				}
				else
				{
					if(color[arr[pop].get(i)]==color[pop])
					{
						return false;
					}
				}
			}
		}
		return true;
	}
	static void run(int n,int k)
	{
		if(dis[n]==0)
		{
			q.add(n);
			dis[n]=k;
		}
		else
		{
			if(dis[n]>k)
				dis[n]=k;
		}
	}
	private static int[] nextIntArray(InputReader in,int n)
	{
		int[] a=new int[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();
		return a;
	}
	public static double dis(double x1,double x2,double y1)
	{
		return Math.sqrt(((x1-x2)*(x1-x2))+(y1*y1));
	}
	private static String[] nextStringArray(InputReader in,int n)
	{
		String[] a=new String[n];
		for(int i=0;i<n;i++)
			a[i]=in.next();
		return a;
	}
	private static void show(int[] a)
	{
		for(int i=0;i<a.length;i++)
			System.out.print(a[i]+" ");
		System.out.println();
	}
	private static void show2DArray(char[][] a)
	{
		for(int i=0;i<a.length;i++)
		{
			for(int j=0;j<a[0].length;j++)
				System.out.print(a[i][j]);
			System.out.println();
		}
	}
 static long fact(long x)
 {
	 long i=x,mul=1;
	 while(i>0)
	 {
		 mul=(mul%1000000007)*(i%1000000007)%1000000007;
		 i--;
	 }
	 return mul;
 }
 static class LengthComparator implements Comparator<String> {
	    public int compare(String arg0, String arg1) {
		// Use Integer.compare to compare the two Strings' lengths.
		return (arg0+arg1).compareTo(arg1+arg0);
	    }
	}
// static long output(ArrayList<Integer> h[],int j,boolean[] v)
// {
//	 int k;
//	 v[j]=true;
//	 sum++;
//	 for(k=0;k<h[j].size();k++)
//	 {
//		 if(v[h[j].get(k)]==false)
//		 {
//			 output(h,h[j].get(k),v);
//		 }
//	 }
//	 return sum;
// }
 static long func(boolean v[],int j,ArrayList<Integer> h[],long ban[])
 {
	 	v[j]=true;
	 	 int k;
	 	long sum=0;
	    sum=sum+ban[j];
	 	//System.out.println(h[j].size());
	 	for(k=0;k<h[j].size();k++)
	 	{
	 		if(v[h[j].get(k)]==false)
	 		{
	 			v[h[j].get(k)]=true;
	 			sum+=func(v,h[j].get(k),h,ban);
	 		}
	 	}
	 	return sum;
 }
/*static class Graph {

    	private static Deque<Integer> stack = new ArrayDeque<Integer>();
 		private int least,count,v;

		Set<Integer>[] cities;
    	private int[] risk;

    	Graph(int n,String[] risk){

    		cities = new HashSet[n];
    		this.risk = new int[n];
    		for(int i =0;i<n;i++){
    			cities[i] = new HashSet<>();
    		}
    		for(int i =0;i<n;i++){
    			this.risk[i] = Integer.parseInt(risk[i]);
    		}
    		visited = new boolean[n];
    	}

    	public void add(int x,int y){
    		cities[x].add(y);
    		cities[y].add(x);
    	}
}*/
	static int root(int arr[],int i)
	{
		while(arr[i]!=i)
		{
			i=arr[i];
		}
		return i;
	}
	static boolean find(int arr[],int a,int b)
	{
		if(root(arr,a)==root(arr,b))
		{
			return true;
		}
		else
			return false;
	}
	static void weighted_union(int arr[],int size[],int a,int b)
	{
		int root_a=root(arr,a);
		int root_b=root(arr,b);
		if(root_a!=root_b)
		{
			if(size[root_a]<size[root_b])
			{
				arr[root_a]=arr[root_b];
				size[root_b]+=size[root_a];
			}
			else
			{
				arr[root_b]=arr[root_a];
				size[root_a]+=size[root_b];
			}
		//	count--;
		}
	}
	static class Pair implements Comparable<Pair>
	{
		private long first;
		private long index;
		//private long second;;

		public Pair(long i, long j)
		{
			this.first = i;
			this.index = j;
		}
		public long getFirst() { return first; }
		//public long getSecond() { return second; }
		public long getIndex() { return index ;}
		public void setFirst(long k) { this.first=k ; }
		public void setIndex(long k) { this.index=k ;}
		//public void setSecond(long k) { this.second=k ;}
		@Override
		public int compareTo(Pair o)
		{
			return Long.compare(this.first, o.first);
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}

}


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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	public static String tallestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l+1)/2;

			if(a[mid]<h)
			{
				f=mid;
			}
			else
			{
				l=mid-1;
			}

		}
		if(a[f]>=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	public static String shortestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l)/2;

			if(a[mid]>h)
			{
				l=mid;
			}
			else
			{
				f=mid+1;
			}

		}
		if(a[f]<=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	/*public static void main(String[] args) throws IOException{
		int N=sc.nextInt();
		a= new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}

		int Q=sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int height=sc.nextInt();
			System.out.println(tallestChimp(height) + " " + shortestChimp(height));

		}
	}*/

	/*public static void main(String[] args) throws IOException {
		int N=sc.nextInt();
		int Q=sc.nextInt();
		int count=1;
		while(N!=0 && Q!=0)
		{
			System.out.println("CASE# "+ count + ":");
			int[] a= new int[N];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for (int i = 0; i < Q; i++) {
				int temp=sc.nextInt();
				int f=0;
				int l=a.length-1;
				while (f<l) {
					int middle=(f+l)/2;
					if(a[middle]>temp)
					{
						l=middle-1;
					}
					else if(a[middle]==temp)
					{
						l=middle;
					}
					else
					{
						f=middle+1;
					}

				}
				if(a[f]!=temp)
				{
					System.out.println(temp + " not found");
				}
				else
				{
					f++;
					System.out.println(temp + " found at " + f);
				}
			}
			N=sc.nextInt();
			Q=sc.nextInt();
			count++;
		}

	}*/
	public static boolean nLines(int n, int v, int k)
	{
		long sum=0;
		long d=1;
		while(v/d!=0)
		{
			sum+=v/d;
			d*=k;
		}

		if(sum>=n)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		int f=1;
		int l=n;
		while(f<l)
		{
			int middle=(f+l)/2;
			if(nLines(n,middle,k))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}

		}
		System.out.println(f);
	}*/
	public static boolean canBuy(int k, int s)
	{
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long)(a[i]+(i+1)*k);
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < k; i++) {
			if(b[i]<0 || b[i]>s || b[i]+sum>s)
			{
				return false;
			}
			sum+=b[i];
		}
		if(sum<=s)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int S=sc.nextInt();
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/

	/*public static void main(String[] args) throws IOException {
		int n=100000 ;
		int S=1000000000;
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=100000;
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			System.out.println(f + " " + l);
			System.out.println("middle: " + middle);
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/
	public static boolean fillContainers(int m, int size)
	{
		int curr=0;
		int nFilled=0;
		for (int i = 0; i < a.length; i++) {
			if(a[i]>size)
			{
				return false;
			}
			if(curr+a[i]<=size)
			{
				curr+=a[i];
			}
			else
			{
				nFilled++;
				curr=a[i];
			}
		}
		nFilled++;
		if(nFilled<=m)
		return true;
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		while(true)
		{
			int sum=0;
			a=new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				sum+=a[i];
			}

			int f=1;
			int l=sum;

			while(f<l)
			{
				int middle=(f+l)/2;
				if(fillContainers(m, middle))
				{
					l=middle;
				}
				else
				{
					f=middle+1;
				}
			}
			System.out.println(f);
			if(!sc.ready())
			{
				break;
			}
			n=sc.nextInt();
			m=sc.nextInt();
		}

	}*/

	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		double[] a= new double[n];

		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextDouble();
		}

		double f=0;
		double l=1000;

		for (int i = 0; i < 100; i++) {
			double middle=(f+l)/2;
			//System.out.println(f + " " + l);
			//System.out.println("middle: " + middle);
			double energy=0;

			for (int j = 0; j < a.length; j++) {
				if(a[j]-middle>0)
				{
					double x=a[j]-middle;
					energy+=x-(x*k)/100;
				}
				else
				{
					double x=a[j]-middle;
					energy+=x;
				}
			}
			//System.out.println("energy: " + energy);
			if(energy>0)
			{
				f=middle;
			}
			else
			{
				l=middle;
			}
		}
		System.out.println(f);
		//System.out.println(Arrays.toString(a));
	}*/

	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

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

		long f=0;
		long l=1000000000;
			l=l*100000000;

		while(f<l)
		{
			//System.out.println(f + " " + l);
			long middle=(f+l)/2;
			//System.out.println(middle);

			if(canRemove(middle, m))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}
		}
		System.out.println(f);
	}
	public static boolean canRemove(long time, int m) {
		int i=0;
		int[] piles=Arrays.copyOf(a, a.length);
		while(m>0 && i<a.length)
		{
			long t=time-1-i;
			while(t>0 && i<a.length)
			{
				if(piles[i]>0)
				{
					if(t-piles[i]>=0)
					{
						t=t-piles[i];
						piles[i]=0;
					}
					else
					{
						piles[i]=piles[i]-(int)t;
						t=0;
					}
				}
				else
				{
					i++;
					t--;
				}
			}
			m--;
		}
		for (int j = 0; j < piles.length; j++) {
			if(piles[j]!=0)
			{
				return false;
			}
		}
		return true;
	}
	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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		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.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	public static String tallestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l+1)/2;

			if(a[mid]<h)
			{
				f=mid;
			}
			else
			{
				l=mid-1;
			}

		}
		if(a[f]>=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	public static String shortestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l)/2;

			if(a[mid]>h)
			{
				l=mid;
			}
			else
			{
				f=mid+1;
			}

		}
		if(a[f]<=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	/*public static void main(String[] args) throws IOException{
		int N=sc.nextInt();
		a= new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}

		int Q=sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int height=sc.nextInt();
			System.out.println(tallestChimp(height) + " " + shortestChimp(height));

		}
	}*/

	/*public static void main(String[] args) throws IOException {
		int N=sc.nextInt();
		int Q=sc.nextInt();
		int count=1;
		while(N!=0 && Q!=0)
		{
			System.out.println("CASE# "+ count + ":");
			int[] a= new int[N];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for (int i = 0; i < Q; i++) {
				int temp=sc.nextInt();
				int f=0;
				int l=a.length-1;
				while (f<l) {
					int middle=(f+l)/2;
					if(a[middle]>temp)
					{
						l=middle-1;
					}
					else if(a[middle]==temp)
					{
						l=middle;
					}
					else
					{
						f=middle+1;
					}

				}
				if(a[f]!=temp)
				{
					System.out.println(temp + " not found");
				}
				else
				{
					f++;
					System.out.println(temp + " found at " + f);
				}
			}
			N=sc.nextInt();
			Q=sc.nextInt();
			count++;
		}

	}*/
	public static boolean nLines(int n, int v, int k)
	{
		long sum=0;
		long d=1;
		while(v/d!=0)
		{
			sum+=v/d;
			d*=k;
		}

		if(sum>=n)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		int f=1;
		int l=n;
		while(f<l)
		{
			int middle=(f+l)/2;
			if(nLines(n,middle,k))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}

		}
		System.out.println(f);
	}*/
	public static boolean canBuy(int k, int s)
	{
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long)(a[i]+(i+1)*k);
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < k; i++) {
			if(b[i]<0 || b[i]>s || b[i]+sum>s)
			{
				return false;
			}
			sum+=b[i];
		}
		if(sum<=s)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int S=sc.nextInt();
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/

	/*public static void main(String[] args) throws IOException {
		int n=100000 ;
		int S=1000000000;
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=100000;
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			System.out.println(f + " " + l);
			System.out.println("middle: " + middle);
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/
	public static boolean fillContainers(int m, int size)
	{
		int curr=0;
		int nFilled=0;
		for (int i = 0; i < a.length; i++) {
			if(a[i]>size)
			{
				return false;
			}
			if(curr+a[i]<=size)
			{
				curr+=a[i];
			}
			else
			{
				nFilled++;
				curr=a[i];
			}
		}
		nFilled++;
		if(nFilled<=m)
		return true;
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		while(true)
		{
			int sum=0;
			a=new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				sum+=a[i];
			}

			int f=1;
			int l=sum;

			while(f<l)
			{
				int middle=(f+l)/2;
				if(fillContainers(m, middle))
				{
					l=middle;
				}
				else
				{
					f=middle+1;
				}
			}
			System.out.println(f);
			if(!sc.ready())
			{
				break;
			}
			n=sc.nextInt();
			m=sc.nextInt();
		}

	}*/

	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		double[] a= new double[n];

		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextDouble();
		}

		double f=0;
		double l=1000;

		for (int i = 0; i < 100; i++) {
			double middle=(f+l)/2;
			//System.out.println(f + " " + l);
			//System.out.println("middle: " + middle);
			double energy=0;

			for (int j = 0; j < a.length; j++) {
				if(a[j]-middle>0)
				{
					double x=a[j]-middle;
					energy+=x-(x*k)/100;
				}
				else
				{
					double x=a[j]-middle;
					energy+=x;
				}
			}
			//System.out.println("energy: " + energy);
			if(energy>0)
			{
				f=middle;
			}
			else
			{
				l=middle;
			}
		}
		System.out.println(f);
		//System.out.println(Arrays.toString(a));
	}*/

	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

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

		long f=0;
		long l=1000000000;
			l=l*100000;

		while(f<l)
		{
			//System.out.println(f + " " + l);
			long middle=(f+l)/2;
			//System.out.println(middle);

			if(canRemove(middle, m))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}
		}
		System.out.println(f);
	}
	public static boolean canRemove(long time, int m) {
		int i=0;
		int[] piles=Arrays.copyOf(a, a.length);
		while(m>0 && i<a.length)
		{
			long t=time-1-i;
			while(t>0 && i<a.length)
			{
				if(piles[i]>0)
				{
					if(t-piles[i]>=0)
					{
						t=t-piles[i];
						piles[i]=0;
					}
					else
					{
						piles[i]=piles[i]-(int)t;
						t=0;
					}
				}
				else
				{
					i++;
					t--;
				}
			}
			m--;
		}
		for (int j = 0; j < piles.length; j++) {
			if(piles[j]!=0)
			{
				return false;
			}
		}
		return true;
	}
	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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		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.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	public static String tallestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l+1)/2;

			if(a[mid]<h)
			{
				f=mid;
			}
			else
			{
				l=mid-1;
			}

		}
		if(a[f]>=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	public static String shortestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l)/2;

			if(a[mid]>h)
			{
				l=mid;
			}
			else
			{
				f=mid+1;
			}

		}
		if(a[f]<=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	/*public static void main(String[] args) throws IOException{
		int N=sc.nextInt();
		a= new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}

		int Q=sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int height=sc.nextInt();
			System.out.println(tallestChimp(height) + " " + shortestChimp(height));

		}
	}*/

	/*public static void main(String[] args) throws IOException {
		int N=sc.nextInt();
		int Q=sc.nextInt();
		int count=1;
		while(N!=0 && Q!=0)
		{
			System.out.println("CASE# "+ count + ":");
			int[] a= new int[N];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for (int i = 0; i < Q; i++) {
				int temp=sc.nextInt();
				int f=0;
				int l=a.length-1;
				while (f<l) {
					int middle=(f+l)/2;
					if(a[middle]>temp)
					{
						l=middle-1;
					}
					else if(a[middle]==temp)
					{
						l=middle;
					}
					else
					{
						f=middle+1;
					}

				}
				if(a[f]!=temp)
				{
					System.out.println(temp + " not found");
				}
				else
				{
					f++;
					System.out.println(temp + " found at " + f);
				}
			}
			N=sc.nextInt();
			Q=sc.nextInt();
			count++;
		}

	}*/
	public static boolean nLines(int n, int v, int k)
	{
		long sum=0;
		long d=1;
		while(v/d!=0)
		{
			sum+=v/d;
			d*=k;
		}

		if(sum>=n)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		int f=1;
		int l=n;
		while(f<l)
		{
			int middle=(f+l)/2;
			if(nLines(n,middle,k))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}

		}
		System.out.println(f);
	}*/
	public static boolean canBuy(int k, int s)
	{
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long)(a[i]+(i+1)*k);
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < k; i++) {
			if(b[i]<0 || b[i]>s || b[i]+sum>s)
			{
				return false;
			}
			sum+=b[i];
		}
		if(sum<=s)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int S=sc.nextInt();
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/

	/*public static void main(String[] args) throws IOException {
		int n=100000 ;
		int S=1000000000;
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=100000;
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			System.out.println(f + " " + l);
			System.out.println("middle: " + middle);
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/
	public static boolean fillContainers(int m, int size)
	{
		int curr=0;
		int nFilled=0;
		for (int i = 0; i < a.length; i++) {
			if(a[i]>size)
			{
				return false;
			}
			if(curr+a[i]<=size)
			{
				curr+=a[i];
			}
			else
			{
				nFilled++;
				curr=a[i];
			}
		}
		nFilled++;
		if(nFilled<=m)
		return true;
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		while(true)
		{
			int sum=0;
			a=new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				sum+=a[i];
			}

			int f=1;
			int l=sum;

			while(f<l)
			{
				int middle=(f+l)/2;
				if(fillContainers(m, middle))
				{
					l=middle;
				}
				else
				{
					f=middle+1;
				}
			}
			System.out.println(f);
			if(!sc.ready())
			{
				break;
			}
			n=sc.nextInt();
			m=sc.nextInt();
		}

	}*/

	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		double[] a= new double[n];

		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextDouble();
		}

		double f=0;
		double l=1000;

		for (int i = 0; i < 100; i++) {
			double middle=(f+l)/2;
			//System.out.println(f + " " + l);
			//System.out.println("middle: " + middle);
			double energy=0;

			for (int j = 0; j < a.length; j++) {
				if(a[j]-middle>0)
				{
					double x=a[j]-middle;
					energy+=x-(x*k)/100;
				}
				else
				{
					double x=a[j]-middle;
					energy+=x;
				}
			}
			//System.out.println("energy: " + energy);
			if(energy>0)
			{
				f=middle;
			}
			else
			{
				l=middle;
			}
		}
		System.out.println(f);
		//System.out.println(Arrays.toString(a));
	}*/

	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		a= new int[n];
		int indx=0;
		long sum=0;
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
			if(a[i]!=0)
			{
				indx=i;
			}
			sum+=a[i];
		}
		long ppl=m;
		if(sum<m)
		{
			ppl=sum;
		}

		long b=0;
		if(sum%ppl!=0)
		{
			if(sum%(sum/ppl+1)==a[indx])
			{
				b=sum%(sum/ppl+1);

			}
			else
			{
				b=sum/ppl+1;
			}
		}
		else
		{
			b=sum/ppl;
		}

		long t=indx +1 + b;
		System.out.println(t);

	}

	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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		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.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	public static String tallestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l+1)/2;

			if(a[mid]<h)
			{
				f=mid;
			}
			else
			{
				l=mid-1;
			}

		}
		if(a[f]>=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	public static String shortestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l)/2;

			if(a[mid]>h)
			{
				l=mid;
			}
			else
			{
				f=mid+1;
			}

		}
		if(a[f]<=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	/*public static void main(String[] args) throws IOException{
		int N=sc.nextInt();
		a= new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}

		int Q=sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int height=sc.nextInt();
			System.out.println(tallestChimp(height) + " " + shortestChimp(height));

		}
	}*/

	/*public static void main(String[] args) throws IOException {
		int N=sc.nextInt();
		int Q=sc.nextInt();
		int count=1;
		while(N!=0 && Q!=0)
		{
			System.out.println("CASE# "+ count + ":");
			int[] a= new int[N];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for (int i = 0; i < Q; i++) {
				int temp=sc.nextInt();
				int f=0;
				int l=a.length-1;
				while (f<l) {
					int middle=(f+l)/2;
					if(a[middle]>temp)
					{
						l=middle-1;
					}
					else if(a[middle]==temp)
					{
						l=middle;
					}
					else
					{
						f=middle+1;
					}

				}
				if(a[f]!=temp)
				{
					System.out.println(temp + " not found");
				}
				else
				{
					f++;
					System.out.println(temp + " found at " + f);
				}
			}
			N=sc.nextInt();
			Q=sc.nextInt();
			count++;
		}

	}*/
	public static boolean nLines(int n, int v, int k)
	{
		long sum=0;
		long d=1;
		while(v/d!=0)
		{
			sum+=v/d;
			d*=k;
		}

		if(sum>=n)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		int f=1;
		int l=n;
		while(f<l)
		{
			int middle=(f+l)/2;
			if(nLines(n,middle,k))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}

		}
		System.out.println(f);
	}*/
	public static boolean canBuy(int k, int s)
	{
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long)(a[i]+(i+1)*k);
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < k; i++) {
			if(b[i]<0 || b[i]>s || b[i]+sum>s)
			{
				return false;
			}
			sum+=b[i];
		}
		if(sum<=s)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int S=sc.nextInt();
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/

	/*public static void main(String[] args) throws IOException {
		int n=100000 ;
		int S=1000000000;
		a=new int[n];
		for (int i = 0; i < a.lngth; i++) {
			a[i]=100000;
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			System.out.println(f + " " + l);
			System.out.println("middle: " + middle);
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/
	public static boolean fillContainers(int m, int size)
	{
		int curr=0;
		int nFilled=0;
		for (int i = 0; i < a.length; i++) {
			if(a[i]>size)
			{
				return false;
			}
			if(curr+a[i]<=size)
			{
				curr+=a[i];
			}
			else
			{
				nFilled++;
				curr=a[i];
			}
		}
		nFilled++;
		if(nFilled<=m)
		return true;
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		while(true)
		{
			int sum=0;
			a=new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				sum+=a[i];
			}

			int f=1;
			int l=sum;

			while(f<l)
			{
				int middle=(f+l)/2;
				if(fillContainers(m, middle))
				{
					l=middle;
				}
				else
				{
					f=middle+1;
				}
			}
			System.out.println(f);
			if(!sc.ready())
			{
				break;
			}
			n=sc.nextInt();
			m=sc.nextInt();
		}

	}*/

	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		double[] a= new double[n];

		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextDouble();
		}

		double f=0;
		double l=1000;

		for (int i = 0; i < 100; i++) {
			double middle=(f+l)/2;
			//System.out.println(f + " " + l);
			//System.out.println("middle: " + middle);
			double energy=0;

			for (int j = 0; j < a.length; j++) {
				if(a[j]-middle>0)
				{
					double x=a[j]-middle;
					energy+=x-(x*k)/100;
				}
				else
				{
					double x=a[j]-middle;
					energy+=x;
				}
			}
			//System.out.println("energy: " + energy);
			if(energy>0)
			{
				f=middle;
			}
			else
			{
				l=middle;
			}
		}
		System.out.println(f);
		//System.out.println(Arrays.toString(a));
	}*/

	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		a= new int[n];
		int indx=0;
		int sum=0;
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
			if(a[i]!=0)
			{
				indx=i;
			}
			sum+=a[i];
		}
		int ppl=m;
		if(sum<m)
		{
			ppl=sum;
		}

		int b=0;
		if(sum%ppl!=0)
		{
			if(sum%(sum/ppl+1)==a[indx])
			{
				b=sum%(sum/ppl+1);

			}
			else
			{
				b=sum/ppl+1;
			}
		}
		else
		{
			b=sum/ppl;
		}

		int t=indx +1 + b;
		System.out.println(t);

	}

	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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		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.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	public static String tallestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l+1)/2;

			if(a[mid]<h)
			{
				f=mid;
			}
			else
			{
				l=mid-1;
			}

		}
		if(a[f]>=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	public static String shortestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l)/2;

			if(a[mid]>h)
			{
				l=mid;
			}
			else
			{
				f=mid+1;
			}

		}
		if(a[f]<=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	/*public static void main(String[] args) throws IOException{
		int N=sc.nextInt();
		a= new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}

		int Q=sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int height=sc.nextInt();
			System.out.println(tallestChimp(height) + " " + shortestChimp(height));

		}
	}*/

	/*public static void main(String[] args) throws IOException {
		int N=sc.nextInt();
		int Q=sc.nextInt();
		int count=1;
		while(N!=0 && Q!=0)
		{
			System.out.println("CASE# "+ count + ":");
			int[] a= new int[N];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for (int i = 0; i < Q; i++) {
				int temp=sc.nextInt();
				int f=0;
				int l=a.length-1;
				while (f<l) {
					int middle=(f+l)/2;
					if(a[middle]>temp)
					{
						l=middle-1;
					}
					else if(a[middle]==temp)
					{
						l=middle;
					}
					else
					{
						f=middle+1;
					}

				}
				if(a[f]!=temp)
				{
					System.out.println(temp + " not found");
				}
				else
				{
					f++;
					System.out.println(temp + " found at " + f);
				}
			}
			N=sc.nextInt();
			Q=sc.nextInt();
			count++;
		}

	}*/
	public static boolean nLines(int n, int v, int k)
	{
		long sum=0;
		long d=1;
		while(v/d!=0)
		{
			sum+=v/d;
			d*=k;
		}

		if(sum>=n)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		int f=1;
		int l=n;
		while(f<l)
		{
			int middle=(f+l)/2;
			if(nLines(n,middle,k))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}

		}
		System.out.println(f);
	}*/
	public static boolean canBuy(int k, int s)
	{
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long)(a[i]+(i+1)*k);
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < k; i++) {
			if(b[i]<0 || b[i]>s || b[i]+sum>s)
			{
				return false;
			}
			sum+=b[i];
		}
		if(sum<=s)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int S=sc.nextInt();
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/

	/*public static void main(String[] args) throws IOException {
		int n=100000 ;
		int S=1000000000;
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=100000;
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			System.out.println(f + " " + l);
			System.out.println("middle: " + middle);
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/
	public static boolean fillContainers(int m, int size)
	{
		int curr=0;
		int nFilled=0;
		for (int i = 0; i < a.length; i++) {
			if(a[i]>size)
			{
				return false;
			}
			if(curr+a[i]<=size)
			{
				curr+=a[i];
			}
			else
			{
				nFilled++;
				curr=a[i];
			}
		}
		nFilled++;
		if(nFilled<=m)
		return true;
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		while(true)
		{
			int sum=0;
			a=new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				sum+=a[i];
			}

			int f=1;
			int l=sum;

			while(f<l)
			{
				int middle=(f+l)/2;
				if(fillContainers(m, middle))
				{
					l=middle;
				}
				else
				{
					f=middle+1;
				}
			}
			System.out.println(f);
			if(!sc.ready())
			{
				break;
			}
			n=sc.nextInt();
			m=sc.nextInt();
		}

	}*/

	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		double[] a= new double[n];

		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextDouble();
		}

		double f=0;
		double l=1000;

		for (int i = 0; i < 100; i++) {
			double middle=(f+l)/2;
			//System.out.println(f + " " + l);
			//System.out.println("middle: " + middle);
			double energy=0;

			for (int j = 0; j < a.length; j++) {
				if(a[j]-middle>0)
				{
					double x=a[j]-middle;
					energy+=x-(x*k)/100;
				}
				else
				{
					double x=a[j]-middle;
					energy+=x;
				}
			}
			//System.out.println("energy: " + energy);
			if(energy>0)
			{
				f=middle;
			}
			else
			{
				l=middle;
			}
		}
		System.out.println(f);
		//System.out.println(Arrays.toString(a));
	}*/

	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		a= new int[n];
		int indx=0;
		long sum=0;
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
			if(a[i]!=0)
			{
				indx=i;
			}
			sum+=a[i];
		}
		long ppl=m;
		if(sum<m)
		{
			ppl=sum;
		}

		long b=0;
		if(sum%ppl!=0)
		{
			if(sum%(sum/ppl+1)==a[indx])
			{
				b=sum%(sum/ppl+1);

			}
			else
			{
				b=sum/ppl+1;
			}
		}
		else
		{
			b=sum/ppl;
		}

		System.out.println(b);

		long t=indx +1 + b;
		System.out.println(t);

	}

	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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		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.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	public static String tallestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l+1)/2;

			if(a[mid]<h)
			{
				f=mid;
			}
			else
			{
				l=mid-1;
			}

		}
		if(a[f]>=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	public static String shortestChimp(int h)
	{
		int f=0;
		int l=a.length-1;
		int mid=0;
		while(f<l)
		{
			mid=(f+l)/2;

			if(a[mid]>h)
			{
				l=mid;
			}
			else
			{
				f=mid+1;
			}

		}
		if(a[f]<=h)
		{
			return "X";
		}
		return a[f]+ "";
	}

	/*public static void main(String[] args) throws IOException{
		int N=sc.nextInt();
		a= new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}

		int Q=sc.nextInt();
		for (int i = 0; i < Q; i++) {
			int height=sc.nextInt();
			System.out.println(tallestChimp(height) + " " + shortestChimp(height));

		}
	}*/

	/*public static void main(String[] args) throws IOException {
		int N=sc.nextInt();
		int Q=sc.nextInt();
		int count=1;
		while(N!=0 && Q!=0)
		{
			System.out.println("CASE# "+ count + ":");
			int[] a= new int[N];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for (int i = 0; i < Q; i++) {
				int temp=sc.nextInt();
				int f=0;
				int l=a.length-1;
				while (f<l) {
					int middle=(f+l)/2;
					if(a[middle]>temp)
					{
						l=middle-1;
					}
					else if(a[middle]==temp)
					{
						l=middle;
					}
					else
					{
						f=middle+1;
					}

				}
				if(a[f]!=temp)
				{
					System.out.println(temp + " not found");
				}
				else
				{
					f++;
					System.out.println(temp + " found at " + f);
				}
			}
			N=sc.nextInt();
			Q=sc.nextInt();
			count++;
		}

	}*/
	public static boolean nLines(int n, int v, int k)
	{
		long sum=0;
		long d=1;
		while(v/d!=0)
		{
			sum+=v/d;
			d*=k;
		}

		if(sum>=n)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		int f=1;
		int l=n;
		while(f<l)
		{
			int middle=(f+l)/2;
			if(nLines(n,middle,k))
			{
				l=middle;
			}
			else
			{
				f=middle+1;
			}

		}
		System.out.println(f);
	}*/
	public static boolean canBuy(int k, int s)
	{
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long)(a[i]+(i+1)*k);
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < k; i++) {
			if(b[i]<0 || b[i]>s || b[i]+sum>s)
			{
				return false;
			}
			sum+=b[i];
		}
		if(sum<=s)
		{
			return true;
		}
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int S=sc.nextInt();
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/

	/*public static void main(String[] args) throws IOException {
		int n=100000 ;
		int S=1000000000;
		a=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=100000;
		}
		int f=0;
		int l=n;
		while(f<l)
		{
			int middle=(f+l+1)/2;
			System.out.println(f + " " + l);
			System.out.println("middle: " + middle);
			if(canBuy(middle, S))
			{
				f=middle;
			}
			else
			{
				l=middle-1;
			}
		}
		System.out.print(f + " ");
		Long[] b= new Long[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i]=(long) a[i]+(i+1)*f;
		}
		Arrays.sort(b);
		long sum=0;
		for (int i = 0; i < f; i++) {
			sum+=b[i];
		}
		System.out.println(sum);
	}*/
	public static boolean fillContainers(int m, int size)
	{
		int curr=0;
		int nFilled=0;
		for (int i = 0; i < a.length; i++) {
			if(a[i]>size)
			{
				return false;
			}
			if(curr+a[i]<=size)
			{
				curr+=a[i];
			}
			else
			{
				nFilled++;
				curr=a[i];
			}
		}
		nFilled++;
		if(nFilled<=m)
		return true;
		return false;
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		while(true)
		{
			int sum=0;
			a=new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				sum+=a[i];
			}

			int f=1;
			int l=sum;

			while(f<l)
			{
				int middle=(f+l)/2;
				if(fillContainers(m, middle))
				{
					l=middle;
				}
				else
				{
					f=middle+1;
				}
			}
			System.out.println(f);
			if(!sc.ready())
			{
				break;
			}
			n=sc.nextInt();
			m=sc.nextInt();
		}

	}*/

	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int k=sc.nextInt();

		double[] a= new double[n];

		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextDouble();
		}

		double f=0;
		double l=1000;

		for (int i = 0; i < 100; i++) {
			double middle=(f+l)/2;
			//System.out.println(f + " " + l);
			//System.out.println("middle: " + middle);
			double energy=0;

			for (int j = 0; j < a.length; j++) {
				if(a[j]-middle>0)
				{
					double x=a[j]-middle;
					energy+=x-(x*k)/100;
				}
				else
				{
					double x=a[j]-middle;
					energy+=x;
				}
			}
			//System.out.println("energy: " + energy);
			if(energy>0)
			{
				f=middle;
			}
			else
			{
				l=middle;
			}
		}
		System.out.println(f);
		//System.out.println(Arrays.toString(a));
	}*/

	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();

		a= new int[n];
		int indx=0;
		int sum=0;
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
			if(a[i]!=0)
			{
				indx=i;
			}
			sum+=a[i];
		}
		int ppl=m;
		if(sum<m)
		{
			ppl=sum;
		}

		int b=0;
		if(sum%ppl!=0)
		{
			if(sum%(sum/ppl+1)==a[indx])
			{
				b=sum%(sum/ppl+1);

			}
			else
			{
				b=sum/ppl+1;
			}
		}
		else
		{
			b=sum/ppl;
		}

		int t=indx +1 + b;
		System.out.println(t);

	}

	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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}
}


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

public class Main {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		arr = new int[n];
		for (int i = 0; i < n ; i++) {
			arr[i]=sc.nextInt();
		}
		pw.println(res(m));
	    pw.close();
	}
	static PrintWriter pw=new PrintWriter(System.out);
	static int[] arr;
	static long res(int x) {
		long start=1,end=1000000000,ans=-1;
		while (start<=end) {
			long mid=(start+end)/2;
			int[] arr2=arr.clone();
			int c=arr2.length-1;
			for (int i = 0; i < x; i++) {
				while(c>=0 && arr2[c]==0) c--;
				long t=mid-c-1;
				if(t<=0) break;
				while(c>=0 && arr2[c]<=t) t-=arr2[c--];
				if(c>=0) arr2[c]-=t;
			}
			if (c<0) {
				ans=mid;
				end=mid-1;
			}else {
				start=mid+1;
			}
		}
		return ans;
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}

}


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

public class Main {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		arr = new int[n];
		for (int i = 0; i < n ; i++) {
			arr[i]=sc.nextInt();
		}
		pw.println(res(m));
	    pw.close();
	}
	static PrintWriter pw=new PrintWriter(System.out);
	static int[] arr;
	static int res(int x) {
		int start=1,end=1000000000,ans=-1;
		while (start<=end) {
			int mid=(start+end)/2;
			int[] arr2=arr.clone();
			int c=arr2.length-1;
			for (int i = 0; i < x; i++) {
				while(c>=0 && arr2[c]==0) c--;
				long t=mid-c-1;
				if(t<=0) break;
				while(c>=0 && arr2[c]<=t) t-=arr2[c--];
				if(c>=0) arr2[c]-=t;
			}
			if (c<0) {
				ans=mid;
				end=mid-1;
			}else {
				start=mid+1;
			}
		}
		return ans;
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}

}


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

public class Main {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		arr = new int[n];
		for (int i = 0; i < n ; i++) {
			arr[i]=sc.nextInt();
		}
		pw.println(res(m));
	    pw.close();
	}
	static PrintWriter pw=new PrintWriter(System.out);
	static int[] arr;
	static int res(int x) {
		long start=1,end=1000000000,ans=-1;
		while (start<=end) {
			long mid=(start+end)/2;
			int[] arr2=arr.clone();
			int c=arr2.length-1;
			for (int i = 0; i < x; i++) {
				while(c>=0 && arr2[c]==0) c--;
				long t=mid-c-1;
				if(t<=0) break;
				while(c>=0 && arr2[c]<=t) t-=arr2[c--];
				if(c>=0) arr2[c]-=t;
			}
			if (c<0) {
				ans=mid;
				end=mid-1;
			}else {
				start=mid+1;
			}
		}
		return ans;
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}

}


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

public class Main {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		arr = new int[n];
		for (int i = 0; i < n ; i++) {
			arr[i]=sc.nextInt();
			sum+=arr[i];
		}
		pw.println(res(m));
	    pw.close();
	}
	static PrintWriter pw=new PrintWriter(System.out);
	static int[] arr;
	static long sum=0;
	static long res(int x) {
		long start=2,end=sum+arr.length,ans=-1;
		while (start<=end) {
			long mid=(start+end)/2;
			int[] arr2=arr.clone();
			int c=arr2.length-1;
			for (int i = 0; i < x; i++) {
				while(c>=0 && arr2[c]==0) c--;
				long t=mid-c-1;
				if(t<=0) break;
				while(c>=0 && arr2[c]<=t) t-=arr2[c--];
				if(c>=0) arr2[c]-=t;
			}
			if (c<0) {
				ans=mid;
				end=mid-1;
			}else {
				start=mid+1;
			}
		}
		return ans;
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}

}


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

public class Main {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		arr = new int[n];
		for (int i = 0; i < n ; i++) {
			arr[i]=sc.nextInt();
			sum+=arr[i];
		}
		pw.println(res(m));
	    pw.close();
	}
	static PrintWriter pw=new PrintWriter(System.out);
	static int[] arr;
	static int sum=0;
	static long res(int x) {
		long start=2,end=sum+arr.length,ans=-1;
		while (start<=end) {
			long mid=(start+end)/2;
			int[] arr2=arr.clone();
			int c=arr2.length-1;
			for (int i = 0; i < x; i++) {
				while(c>=0 && arr2[c]==0) c--;
				long t=mid-c-1;
				if(t<=0) break;
				while(c>=0 && arr2[c]<=t) t-=arr2[c--];
				if(c>=0) arr2[c]-=t;
			}
			if (c<0) {
				ans=mid;
				end=mid-1;
			}else {
				start=mid+1;
			}
		}
		return ans;
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}

}


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.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) {
			int t = (int) ((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++) {
				int s = t - (i + 1);
				while (s > 0 && i >= 0) {
					int 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);
	}
}