#include<bits/stdc++.h>

int main(){
    using namespace std;
    size_t n, k;
    cin >> n >> k;
    vector<size_t> w(n);
    for(auto& i : w)cin >> i;
    
    size_t lower = *max_element(w.begin(), w.end()) - 1, upper = 10000000000000;
    while(lower + 1 < upper){
        auto mid = (lower + upper) / 2;
        size_t tmp = 0, a = 0;
        for(const auto i : w){
            if(tmp + i > mid && !(tmp = 0))++a;
            tmp += i;
        }
        (a >= k ? lower : upper) = mid;
    }
    cout << upper << endl;
}
