def check(w,k,mid):
  weight=mid
  remains=k
  flag=True
  for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

  return flag



n,k=map(int,input().split())
w=[]

for i in range(n):
  a=int(input())
  w.append(a)

left=max(w)
right=sum(w)
mid=0

while(1):
  mid=int((left+right)/2)
  #print(left,mid,right)
  if check(w,k,mid):
    right=mid
  else:
    left=mid+1

  if left>=right:
    print(left)
    break def check(w,k,mid):
  weight=mid
  remains=k
  flag=True
  for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

  return flag check weight=mid weight mid remains=k remains k flag=True flag True for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

   i range(len(w)) range len(w) len w if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

   weight>=w[i] weight w[i] w i weight-=w[i] weight w[i] w i remains-=1 remains 1 if remains==0:
        flag=False
        break
       remains==0 remains 0 flag=False flag False break weight=mid weight mid weight-=w[i] weight w[i] w i return flag flag w w k k mid mid n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w=[] w [] for i in range(n):
  a=int(input())
  w.append(a) i range(n) range n a=int(input()) a int(input()) int input() input w.append(a) w.append w append a left=max(w) left max(w) max w right=sum(w) right sum(w) sum w mid=0 mid 0 while(1):
  mid=int((left+right)/2)
  #print(left,mid,right)
  if check(w,k,mid):
    right=mid
  else:
    left=mid+1

  if left>=right:
    print(left)
    break 1 mid=int((left+right)/2) mid int((left+right)/2) int (left+right)/2 left+right left right 2 if check(w,k,mid):
    right=mid
  else:
    left=mid+1

   check(w,k,mid) check w k mid right=mid right mid left=mid+1 left mid+1 mid 1 if left>=right:
    print(left)
    break left>=right left right print(left) print left break a=int(input()) int(input()) a right=mid mid right mid=0 0 mid w=[] [] w left=mid+1 mid+1 left k=map(int,input().split()) map(int,input().split()) k def check(w,k,mid):
  weight=mid
  remains=k
  flag=True
  for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

  return flag def check(w,k,mid):
  weight=mid
  remains=k
  flag=True
  for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

  return flag check n,k=map(int,input().split()) map(int,input().split()) n mid=int((left+right)/2) int((left+right)/2) mid left=max(w) max(w) left right=sum(w) sum(w) right
def check(w,k,mid):
  weight=mid
  remains=k
  flag=True
  for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

  return flag



n,k=map(int,input().split())
w=[]

for i in range(n):
  a=int(input())
  w.append(a)

left=max(w)
right=sum(w)
mid=0

while(1):
  mid=int((left+right)/2)
  #print(left,mid,right)
  if check(w,k,mid):
    right=mid
  else:
    left=mid+1

  if left>=right:
    print(left)
    break
