def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count


n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = 1
right = sum(W)
while left < right:
    mid = (left + right) / 2
    v = maxStack(k, mid, W)
    if v >= n:
        right = mid
    else:
        left = mid + 1
print left def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count maxStack nw = 0 nw 0 count = 0 count 0 t = 1 t 1 for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
     x W if x > p:
            return count
         x > p x p return count count if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
     nw + x <= p nw + x nw x p nw += x nw x count += 1 count 1 if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
     t == k t k return count count t += 1 t 1 nw = x nw x count += 1 count 1 return count count k k p p W W n, k = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split k int(raw_input()) for i in xrange(n) for i in xrange(n) i xrange(n) xrange n for i in xrange(n) int(raw_input()) int raw_input() raw_input W = [int(raw_input()) for i in xrange(n)] W [int(raw_input()) for i in xrange(n)] left = 1 left 1 right = sum(W) right sum(W) sum W while left < right:
    mid = (left + right) / 2
    v = maxStack(k, mid, W)
    if v >= n:
        right = mid
    else:
        left = mid + 1 left < right left right mid = (left + right) / 2 mid (left + right) / 2 left + right left right 2 v = maxStack(k, mid, W) v maxStack(k, mid, W) maxStack k mid W if v >= n:
        right = mid
    else:
        left = mid + 1 v >= n v n right = mid right mid left = mid + 1 left mid + 1 mid 1 print W = [int(raw_input()) for i in xrange(n)] [int(raw_input()) for i in xrange(n)] W n, k = map(int, raw_input().split()) map(int, raw_input().split()) n k = map(int, raw_input().split()) map(int, raw_input().split()) k mid = (left + right) / 2 (left + right) / 2 mid left = mid + 1 mid + 1 left left = 1 1 left def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count maxStack right = sum(W) sum(W) right v = maxStack(k, mid, W) maxStack(k, mid, W) v right = mid mid right
def maxStack(k, p, W):
    nw = 0
    count = 0
    t = 1
    for x in W:
        if x > p:
            return count
        if nw + x <= p:
            nw += x
            count += 1
        else:
            if t == k:
                return count
            else:
                t += 1
                nw = x
                count += 1
    return count


n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = 1
right = sum(W)
while left < right:
    mid = (left + right) / 2
    v = maxStack(k, mid, W)
    if v >= n:
        right = mid
    else:
        left = mid + 1
print left