### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    st = 0
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            st += s
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\tfalse track:{}/{} s:{}".format(t,k,s))
                return st
        else:
            s = x

#    print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
    return 0

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨???????????¨????°????????±???????
    P = 0
    total = 0
    min = 100000
    for w in wi:
        if P < w:
            P = w
        if min > w:
            min = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
    if P < na:
        P = na
    if P < ka:
        P = ka
    z = 0
    while P <= total:
        st = kenzan(P, wi, n, k)
        if st == 0:
            a = P - z
            b = P
            break
        z = int((total-st)/k)
        P += z
    
    while b - a > 1:
#        print("P:{} MAX:{} MIN:{}".format(P, b, a))
        x = int((b - a) / 2)
        if x < 1:
            x = 1
        P = x + a
        st = kenzan(P, wi, n, k)
        if st == 0:
            b = P
        else:
            a = P

    print(P)


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    st = 0
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            st += s
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
                return st
        else:
            s = x

#    print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
    return 0

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨???????????¨????°????????±???????
    P = 0
    total = 0
    min = 100000
    for w in wi:
        if P < w:
            P = w
        if min > w:
            min = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
    if P < na:
        P = na
    if P < ka:
        P = ka
    z = 0
    while P <= total:
        st = kenzan(P, wi, n, k)
#        print("??????????????°:{} ??????????????°??°:{} ?????????????????§??????:{} ????????????????????????:{} ??????????????????:{} ??????:{}".format(n, k, P, total, st,z))
        if st == 0:
            a = P - z
            b = P
            break
        z = int((total-st)/k)
        if z < 1:
            z = 1
        P += z
    
    while b - a > 0:
        x = int((b - a) / 2)
        if x < 1:
            a = b
        P = x + a
        st = kenzan(P, wi, n, k)
#        print("P:{} MAX:{} MIN:{} sekisai:{}".format(P, b, a, st))
        if st == 0:
            b = P
        else:
            a = P

    print(P)


if __name__ == '__main__':
    main()