#include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef int ll;
ll tb1[100001];
int n, m;
ll go(ll nn) {
ll cnt = 1;
int account = nn;
for (int i = 0; i<n; ++i) {
if (account - tb1[i] >= 0) {
account -= tb1[i];
}
else {
cnt++;
account = nn - tb1[i];
}
}
return cnt;
}
// ll go(ll nn){
// ll cnt = 1;
// int account = 0;
// for(int i=0;i<n;++i){
// if(account + tb1[i] > nn){
// cnt++;
// account = tb1[i];
// }
// else{
// account += tb1[i];
// }
// }
// return cnt;
// }
int main(void) {
ll sum = 0, maxv = 0;
cin >> n >> m;
for (int i = 0; i<n; ++i) {
cin >> tb1[i];
maxv = max(maxv, tb1[i]);
}
ll left = maxv;
ll right = 1987654321; // large value
while (left <= right) {
ll mid = (left + right) / 2; // mid는 정한 가격
//cout << mid << endl;
int tempv = go(mid);
if (tempv > m) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
cout << left << endl;
return 0;
}