#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[5000000], *ptr = buf - 1;
inline int readint(){
int n = 0;
char ch = *++ptr;
while(ch < ‘0‘ || ch > ‘9‘) ch = *++ptr;
while(ch <= ‘9‘ && ch >= ‘0‘){
n = (n << 1) + (n << 3) + ch - ‘0‘;
ch = *++ptr;
}
return n;
}
const int maxn = 100000 + 10;
int N, M, m[maxn];
bool Judge(int mid){
int tot = 0, sum = 0;
for(int i = 1; i <= N; i++){
if(sum + m[i] > mid){
tot++;
sum = m[i];
}
else sum += m[i];
}
return tot < M;
}
int main(){
fread(buf, sizeof(char), sizeof(buf), stdin);
N = readint();
M = readint();
int l = 0, r = 1000000000, mid, ans;
for(int i = 1; i <= N; i++) l = max(l, m[i] = readint());
while(l <= r){
mid = l + r >> 1;
if(Judge(mid)){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
printf("%d\n", ans);
return 0;
}