#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e9 + 9;
int n, m, ans;
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 = 1;
r = M;
while (l < r){
mid = (l + r) / 2;
if (check(mid)){
r = mid;
}else{
l = mid + 1;
}
cout << mid << endl;
}
ans = l;
}
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i ++){
cin >> a[i];
}
BinS();
cout << ans;
system("pause");
return 0;
}