#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;
int tb1[100001];
int sum = 0;
int n, m;
int maxv = 0;
//int maxidx;
int go(int k) {
int temp = k;
int cnt = 1;
for (int i = 0; i < n; ++i) {
int noo = temp - tb1[i];
if (noo >= 0) {
temp = noo;
}
else {
temp = k - tb1[i];
cnt++;
}
}
return cnt;
}
int main(void) {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> tb1[i];
sum += tb1[i];
maxv = max(maxv, tb1[i]);
}
int left = maxv;
int right = sum;
while (left <= right) {
int mid = left + (right - left) / 2;
//cout << mid << endl;
if (go(mid) > m) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
cout << left << endl;
return 0;
}