#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, ans, maxx = -1;
int a[N];
int l, r, mid;
bool check(int temp){
int temp1 = 0, temp2 = 0;
for (int i = 1; i <= n; i ++){
if (temp - temp1 >= a[i]){
temp1 += a[i];
if (i == n){
temp2 ++;
}
}else{
temp2 ++;
temp1 = 0;
temp1 += a[i];
}
}
if (temp2 <= m){
return true;
}else{
return false;
}
}
void BinS(){
l = maxx;
r = N - 5;
while (l < r){
mid = (l + r) / 2;
if (check(mid)){
r = mid;
}else{
l = mid + 1;
}
}
ans = l;
}
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i ++){
cin >> a[i];
maxx = max(maxx, a[i]);
}
BinS();
cout << ans;
system("pause");
return 0;
}