#include<bits/stdc++.h>
using namespace std;
int n,k,i,w[1<<17],ng,ok=1e9,m,t,r;
int f(int m){
  r=1;t=0;
  for(i=0;i<n;i++){
    t+=w[i];
    if(t>m)r++,t=w[i];
    if(w[i]>m)return 0;
  }
  return r<=k;
}
int main(){
  cin>>n>>k;
  for(i=0;i<n;i++)cin>>w[i];
  while(abs(ok-ng)>1){
    m=(ok+ng)/2;
    if(f(m))ok=m;
    else ng=m;
  }
  cout<<ok<<endl;
}

