# your code goes here
#allocation
def ca(n,k,w,b):
    cn=0
    m=0
    l=0
    #print(k)
    while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
    if cn>k:
        return 1
    else:
        return -1
  #  print(d)
def bs(n,k,w,Mx,U):
    while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
    if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U
n,k=(int(i) for i in input().split())
w=[int(input())]
#print(w)
Mx=w[0]
for i in range(1,n):
    w.append(int(input()))
    if w[i]>Mx:
        Mx=w[i]
a=n//k
if n%k!=0:
    a+=1
U=a*Mx
#print(w)
Mx=bs(n,k,w,Mx,U)
print(Mx) def ca(n,k,w,b):
    cn=0
    m=0
    l=0
    #print(k)
    while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
    if cn>k:
        return 1
    else:
        return -1
  #  print(d) ca cn=0 cn 0 m=0 m 0 l=0 l 0 while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
     l <n and cn<=k l <n l n cn<=k cn k d=0 d 0 while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
         d<b and l<n d<b d b l<n l n d+=w[l] d w[l] w l l+=1 l 1 if d>b:
    #        d-=w[l]
            l-=1
         d>b d b l-=1 l 1 cn+=1 cn 1 if cn>k:
        return 1
    else:
        return -1
  #  print(d) cn>k cn k return 1 1 return -1 -1 n n k k w w b b def bs(n,k,w,Mx,U):
    while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
    if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U bs while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
     Mx+1<U Mx+1 Mx 1 U t=U-Mx t U-Mx U Mx t//=2 t 2 t+=Mx t Mx if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
     ca(n,k,w,t)==-1 ca(n,k,w,t) ca n k w t -1 U=t U t Mx=t Mx t if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U ca(n,k,w,Mx)==-1 ca(n,k,w,Mx) ca n k w Mx -1 return Mx Mx return U U n n k k w w Mx Mx U U int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,k=(int(i) for i in input().split()) n (int(i) for i in input().split()) k w=[int(input())] w [int(input())] int(input()) int input() input Mx=w[0] Mx w[0] w 0 for i in range(1,n):
    w.append(int(input()))
    if w[i]>Mx:
        Mx=w[i] i range(1,n) range 1 n w.append(int(input())) w.append w append int(input()) int input() input if w[i]>Mx:
        Mx=w[i] w[i]>Mx w[i] w i Mx Mx=w[i] Mx w[i] w i a=n//k a n//k n k if n%k!=0:
    a+=1 n%k!=0 n%k n k 0 a+=1 a 1 U=a*Mx U a*Mx a Mx Mx=bs(n,k,w,Mx,U) Mx bs(n,k,w,Mx,U) bs n k w Mx U print(Mx) print Mx a+=1 1 a Mx=bs(n,k,w,Mx,U) bs(n,k,w,Mx,U) Mx def ca(n,k,w,b):
    cn=0
    m=0
    l=0
    #print(k)
    while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
    if cn>k:
        return 1
    else:
        return -1
  #  print(d) def ca(n,k,w,b):
    cn=0
    m=0
    l=0
    #print(k)
    while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
    if cn>k:
        return 1
    else:
        return -1
  #  print(d) ca Mx=w[0] w[0] Mx def bs(n,k,w,Mx,U):
    while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
    if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U def bs(n,k,w,Mx,U):
    while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
    if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U bs Mx=w[i] w[i] Mx U=a*Mx a*Mx U n,k=(int(i) for i in input().split()) (int(i) for i in input().split()) n k=(int(i) for i in input().split()) (int(i) for i in input().split()) k w=[int(input())] [int(input())] w a=n//k n//k a
# your code goes here
#allocation
def ca(n,k,w,b):
    cn=0
    m=0
    l=0
    #print(k)
    while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
    if cn>k:
        return 1
    else:
        return -1
  #  print(d)
def bs(n,k,w,Mx,U):
    while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
    if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U
n,k=(int(i) for i in input().split())
w=[int(input())]
#print(w)
Mx=w[0]
for i in range(1,n):
    w.append(int(input()))
    if w[i]>Mx:
        Mx=w[i]
a=n//k
if n%k!=0:
    a+=1
U=a*Mx
#print(w)
Mx=bs(n,k,w,Mx,U)
print(Mx)