
def f(w, n, k, v):
    # how many things in list w of length n can fill in k cars with capacity v?
    i = 0
    space = 0
    while i < n:
        if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
    return i


if __name__ == '__main__':
    n, k = map(int, raw_input().split())
    w = []
    maxv = -1
    for i in range(n):
        x = int(raw_input())
        w.append(x)
        maxv = max(maxv, x)

    left = 0
    right = n * maxv

    # range: (left, right]
    # loop until left + 1 = right, then right is the answer
    # why? because right works, but right - 1 doesn't work
    # so right is the smallest capacity
    while right - left > 1:
        mid = (left + right) / 2
        v = f(w, n, k, mid)
        if v >= n:
            # range: (left, mid]
            # in fact, v cannot > n
            right = mid
        else:
            # range: (mid, right]
            left = mid
    print right def f(w, n, k, v):
    # how many things in list w of length n can fill in k cars with capacity v?
    i = 0
    space = 0
    while i < n:
        if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
    return i f i = 0 i 0 space = 0 space 0 while i < n:
        if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
     i < n i n if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
     space >= w[i] space w[i] w i space -= w[i] space w[i] w i i += 1 i 1 if k == 0:
                break
             k == 0 k 0 break k -= 1 k 1 space = v space v return i i w w n n k k v v if __name__ == '__main__':
    n, k = map(int, raw_input().split())
    w = []
    maxv = -1
    for i in range(n):
        x = int(raw_input())
        w.append(x)
        maxv = max(maxv, x)

    left = 0
    right = n * maxv

    # range: (left, right]
    # loop until left + 1 = right, then right is the answer
    # why? because right works, but right - 1 doesn't work
    # so right is the smallest capacity
    while right - left > 1:
        mid = (left + right) / 2
        v = f(w, n, k, mid)
        if v >= n:
            # range: (left, mid]
            # in fact, v cannot > n
            right = mid
        else:
            # range: (mid, right]
            left = mid
    print right __name__ == '__main__' __name__ '__main__' n, k = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split k w = [] w [] maxv = -1 maxv -1 for i in range(n):
        x = int(raw_input())
        w.append(x)
        maxv = max(maxv, x)

     i range(n) range n x = int(raw_input()) x int(raw_input()) int raw_input() raw_input w.append(x) w.append w append x maxv = max(maxv, x) maxv max(maxv, x) max maxv x left = 0 left 0 right = n * maxv right n * maxv n maxv while right - left > 1:
        mid = (left + right) / 2
        v = f(w, n, k, mid)
        if v >= n:
            # range: (left, mid]
            # in fact, v cannot > n
            right = mid
        else:
            # range: (mid, right]
            left = mid
     right - left > 1 right - left right left 1 mid = (left + right) / 2 mid (left + right) / 2 left + right left right 2 v = f(w, n, k, mid) v f(w, n, k, mid) f w n k mid if v >= n:
            # range: (left, mid]
            # in fact, v cannot > n
            right = mid
        else:
            # range: (mid, right]
            left = mid
     v >= n v n right = mid right mid left = mid left mid print x = int(raw_input()) int(raw_input()) x def f(w, n, k, v):
    # how many things in list w of length n can fill in k cars with capacity v?
    i = 0
    space = 0
    while i < n:
        if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
    return i def f(w, n, k, v):
    # how many things in list w of length n can fill in k cars with capacity v?
    i = 0
    space = 0
    while i < n:
        if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
    return i f right = mid mid right k = map(int, raw_input().split()) map(int, raw_input().split()) k right = n * maxv n * maxv right w = [] [] w n, k = map(int, raw_input().split()) map(int, raw_input().split()) n left = 0 0 left mid = (left + right) / 2 (left + right) / 2 mid maxv = max(maxv, x) max(maxv, x) maxv left = mid mid left v = f(w, n, k, mid) f(w, n, k, mid) v maxv = -1 -1 maxv

def f(w, n, k, v):
    # how many things in list w of length n can fill in k cars with capacity v?
    i = 0
    space = 0
    while i < n:
        if space >= w[i]:
            space -= w[i]
            i += 1
        else:
            # space < w[i]
            if k == 0:
                break
            k -= 1
            space = v
    return i


if __name__ == '__main__':
    n, k = map(int, raw_input().split())
    w = []
    maxv = -1
    for i in range(n):
        x = int(raw_input())
        w.append(x)
        maxv = max(maxv, x)

    left = 0
    right = n * maxv

    # range: (left, right]
    # loop until left + 1 = right, then right is the answer
    # why? because right works, but right - 1 doesn't work
    # so right is the smallest capacity
    while right - left > 1:
        mid = (left + right) / 2
        v = f(w, n, k, mid)
        if v >= n:
            # range: (left, mid]
            # in fact, v cannot > n
            right = mid
        else:
            # range: (mid, right]
            left = mid
    print right
