import sys
n,k=map(int,input().split())
w=list(map(int,sys.stdin.readlines()))
def f():
 c=t=0
 for j in w:
  t+=j
  if t>m:
   t=j
   c+=1
   if c>=k:return 0
 return 1
l,r=max(w),sum(w)
while l<r:
 m=(l+r)//2
 if f():r=m
 else:l=m+1
print(r) import sys sys n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w=list(map(int,sys.stdin.readlines())) w list(map(int,sys.stdin.readlines())) list map(int,sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines def f():
 c=t=0
 for j in w:
  t+=j
  if t>m:
   t=j
   c+=1
   if c>=k:return 0
 return 1 f c=t=0 c 0 =t=0 t 0 for j in w:
  t+=j
  if t>m:
   t=j
   c+=1
   if c>=k:return 0
  j w t+=j t j if t>m:
   t=j
   c+=1
   if c>=k:return 0
  t>m t m t=j t j c+=1 c 1 if c>=k:return 0
  c>=k c k return 1 1 l,r=max(w),sum(w) l max(w) max w r sum(w) sum w while l<r:
 m=(l+r)//2
 if f():r=m
 else:l=m+1 l<r l r m=(l+r)//2 m (l+r)//2 l+r l r 2 if f():r=m
 else:l=m+1 f() f print(r) print r n,k=map(int,input().split()) map(int,input().split()) n k=map(int,input().split()) map(int,input().split()) k l,r=max(w),sum(w) max(w) l w=list(map(int,sys.stdin.readlines())) list(map(int,sys.stdin.readlines())) w def f():
 c=t=0
 for j in w:
  t+=j
  if t>m:
   t=j
   c+=1
   if c>=k:return 0
 return 1 def f():
 c=t=0
 for j in w:
  t+=j
  if t>m:
   t=j
   c+=1
   if c>=k:return 0
 return 1 f m=(l+r)//2 (l+r)//2 m r=max(w),sum(w) sum(w) r
import sys
n,k=map(int,input().split())
w=list(map(int,sys.stdin.readlines()))
def f():
 c=t=0
 for j in w:
  t+=j
  if t>m:
   t=j
   c+=1
   if c>=k:return 0
 return 1
l,r=max(w),sum(w)
while l<r:
 m=(l+r)//2
 if f():r=m
 else:l=m+1
print(r)
