include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int NS = 100005;
int a[NS];
int N, M;
bool check(int mid){
int cnt = 1, nums = 0;
for(int i = 0; i < N; i++) if(a[i] > mid) return true;
for(int i = 0; i < N; i++){
nums += a[i];
if(nums > mid){
cnt++;
nums = a[i];
}
}
if(cnt > M) return true;
else return false;
}
int main(){
cin >> N >> M;
for(int i = 0; i < N; i++) cin >> a[i];
int l = 0, r = 1e9 + 1;
while(l + 1 != r){
int mid = l + r >> 1;
if(check(mid)) l = mid;
else r = mid;
}
cout << r << endl;
return 0;
}