e|445x499](upload://vjrREJ8Ph6gtLthgTem6LM9Xbx7.png)
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
def can_divide(mid):
ans = 0
current = 0
for num in arr:
if current+num <= mid:
current+=num
elif num<=mid:
ans+=1
current=num
if ans>k:
return False
else:
return False
ans += current>0
return ans<=k
left,right = 0, sum(arr)
while(left <right):
mid = (left+right)//2
if can_divide(mid):
right = mid
else:
left = mid+1
print(left)