import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
int l = sc.nextInt();
for(int i = 0; i< n; i++) {
arr[i] = sc.nextInt();
}
System.out.println(binarySearch(arr, n, l));
}
public static int binarySearch(int[] arr, int n, int l) {
int sum =0;
int hi;
int lo = 0;
int ans = -1;
for(int i = 0; i< n; i++) {
sum += arr[i];
lo = Math.max(arr[i], lo);
}
hi = sum;
while(hi >= lo) {
int mid = hi+ (lo-hi)/2;
if(isvalid(arr, mid, l)) {
hi = mid - 1;
ans = mid;
}
else
lo = mid + 1;
}
return ans;
}
public static boolean isvalid(int[] arr, int mid, int l) {
int nl = 1;
int sum = 0;
for(int i = 0; i< arr.length; i++) {
sum += arr[i];
if(sum > mid) {
nl++;
sum = arr[i];
if(nl > l)
return false;
}
}
return true;
}
}