1 /*Author:WNJXYK*/
2 #include<cstdio>
3 using namespace std;
4 int n,m;
5 int money[100010];
6 inline bool check(int x){
7 int cnt=1;
8 int sum=0;
9 for (int i=1;i<=n;i++){
10 if (money[i]>x) return false;
11 if (sum+money[i]>x){
12 cnt++;
13 if (cnt>m) return false;
14 sum=money[i];
15 continue;
16 }
17 sum+=money[i];
18 }
19 if (cnt<=m) return true;
20 }
21 int main(){
22 scanf("%d%d",&n,&m);
23 for (int i=1;i<=n;i++) scanf("%d",&money[i]);
24 int maxm=money[1];
25 int left=0,right=1000000000,mid;
26 while(left<right){
27 int mid=(left+right)/2;
28 if (check(mid)==false){
29 left=mid+1;
30 }else{
31 right=mid;
32 }
33 }
34 printf("%d\n",right);
35 return 0;
36 }