import sys
n,k=map(int,input().split())
w=list(map(int,sys.stdin.readlines()))
def f():
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
 return i
l,r=max(w),sum(w)
while l<r:
 m=(l+r)//2
 if f()>=n: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():
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
 return i f i=0 i 0 for _ in[0]*k:
  s=0
  while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
  _ [0]*k [0] 0 k s=0 s 0 while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
  s+w[i]<=m s+w[i] s w[i] w i m s+=w[i] s w[i] w i i+=1 i 1 if i==n:return n
  i==n i n return i i 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()>=n: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()>=n:r=m
 else:l=m+1 f()>=n f() f n print(r) print r r=max(w),sum(w) sum(w) r k=map(int,input().split()) map(int,input().split()) k def f():
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
 return i def f():
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
 return i f w=list(map(int,sys.stdin.readlines())) list(map(int,sys.stdin.readlines())) w n,k=map(int,input().split()) map(int,input().split()) n l,r=max(w),sum(w) max(w) l m=(l+r)//2 (l+r)//2 m
import sys
n,k=map(int,input().split())
w=list(map(int,sys.stdin.readlines()))
def f():
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=m:
   s+=w[i];i+=1
   if i==n:return n
 return i
l,r=max(w),sum(w)
while l<r:
 m=(l+r)//2
 if f()>=n:r=m
 else:l=m+1
print(r)
