#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
const int MAX_N = 100005;
int n, m;
int money[MAX_N];
bool C(int d) {
int expense = 0;
int months = 1;
for(int i=0; i<n; i++) {
expense = expense + money[i];
if(expense > d) {
expense = money[i];
months++;
}
}
if(months > m) return true;
return false;
}
int main() {
scanf("%d%d", &n, &m);
for(int i=0; i<n; i++)
scanf("%d", &money[i]);
int lb = *max_element(money, money+n);
int ub = accumulate(money, money+n, 0);
while(lb < ub) {
int mid = (lb + ub) / 2;
if(C(mid)) {
lb = mid + 1;
}
else {
ub = mid;
}
}
printf("%d\n", lb);
return 0;
}