#include<bits/stdc++.h>

int main(void){
    int n, k;
    long long int pmax = 10000000000;
    scanf("%d %d", &n, &k);
    std::vector<int> w(n), rui(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &w[i]);
        
    }
    
    int begin = 0;
    int end = n;
    int bi = 0;
    //int be = 1;
    long long int tsum = 0;
    //int p = 6;
    int cnt = 1;
    int ti;
    long long int ans = 1001001001;
    bool flag = false;
    long long int left = 1;
    long long int right = pmax + 1;
    long long int p;
    int tmp;
    //while(true){
        
        while(left != right){
            p = (left + right) / 2;
            if(p == 17){
                 tmp = 1;
            }

            //std::cout << p << std::endl;
            //std::cout << p << std::endl;
            while(bi != end){
                ti = bi;
                while(!flag && bi != end){
                    tsum += w[bi];
                    /*
                    if(p == 17){
                        std::cout << "!!!!!!!!!!!!" << std::endl;
                        std::cout << "w[bi]:" << w[bi] << std::endl;
                        std::cout << "tsum:" << tsum << std::endl;
                        std::cout << "cnt:" << cnt << std::endl;
                    }
                    */
                    if (p == 17){ 
                        /*
                        if(tsum > 17)
                        {   
                            std::cout << "-" << std::endl;
                            tmp++;
                            //std::cout << "w[bi]:" << w[bi] << std::endl;
                        }else{
                            std::cout << "w[bi]:" << w[bi] << std::endl;

                        }
                        */
                    }
                    if(tsum <= p){
                        bi++;
                        /*
                        if(bi == end){
                            cnt++;
                        }
                        */
                        
                        continue;
                    }else if(tsum > p && ti != bi){
                        cnt++;
                        
                        
                        
                        
                        tsum = 0;
                        
                        break;
                    }else{
                        flag = true;
                    }
                }
                if(flag){
                    break;
                }
            }
            
           
            
            /*
            if(!flag && cnt == k){
                
                right = p;
                if(ans > p){
                    ans = p;
                }

                //break;
            }
            */
            if(flag){
                left = p + 1;
                //std::cout << "left:" << left << std::endl;

            }
            if(!flag && cnt <= k){
                right = p;
                 if(ans > p){
                    ans = p;
                }
            }else if(!flag && cnt > k){
                left = p + 1;
                //std::cout << "left:" << left << std::endl;
            }

            cnt = 1;
            tsum = 0;
            bi = 0;
            //p++;
            flag = false;
            //std::cout << p << std::endl;

            //std::cout << left << " " << right << std::endl;
        }
    //}
    std::cout << ans << std::endl;

       

    return 0;
}


Measured memory_bytes: 3624