N,K=gets.split.map &:to_i
W=$<.map &:to_i
l=0
r=$$**3
m=r/2
def a m
i=k=sum=0
while i<N
return 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
a(m)?r=m :l=m
m=(l+r)/2
end
p r