N,K=gets.split.map &:to_i
W=$<.map &:to_i

l=0
r=$$**3
m=r/2

def can? m
  i=0
  k=1
  sum=0
  while i<N
    return false if W[i]>m
    sum+=W[i]
    if m<sum
      sum=W[i]
      k+=1
    end
    i+=1
  end
  k<=K
end

while l+1<r
can?(m) ? r=m : l=m
m=(l+r)/2
end
p l+1