def check(m):
    global n, k, w, presum
    s = 0
    for j in range(k):
        ok = s
        ng = n + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
        s = ok
    if s == n:
        return True
    else:
        return False


def resolve():
    global n, k, w, presum
    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    presum = [0 for _ in range(n + 1)]
    for i in range(n):
        presum[i + 1] = presum[i] + w[i]
    if n <= k:
        print(max(w))
        return
    ok = 100000 * 10000
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


resolve()
 def check(m):
    global n, k, w, presum
    s = 0
    for j in range(k):
        ok = s
        ng = n + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
        s = ok
    if s == n:
        return True
    else:
        return False check global n, k, w, presum s = 0 s 0 for j in range(k):
        ok = s
        ng = n + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
        s = ok
     j range(k) range k ok = s ok s ng = n + 1 ng n + 1 n 1 while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
         abs(ok - ng) > 1 abs(ok - ng) abs ok - ng ok ng 1 mid = (ok + ng) // 2 mid (ok + ng) // 2 ok + ng ok ng 2 if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
         presum[mid] - presum[s] <= m presum[mid] - presum[s] presum[mid] presum mid presum[s] presum s m ok = mid ok mid ng = mid ng mid s = ok s ok if s == n:
        return True
    else:
        return False s == n s n return True True return False False m m def resolve():
    global n, k, w, presum
    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    presum = [0 for _ in range(n + 1)]
    for i in range(n):
        presum[i + 1] = presum[i] + w[i]
    if n <= k:
        print(max(w))
        return
    ok = 100000 * 10000
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok) resolve global n, k, w, presum 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 int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input w = [int(input()) for _ in range(n)] w [int(input()) for _ in range(n)] 0 for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) 0 presum = [0 for _ in range(n + 1)] presum [0 for _ in range(n + 1)] for i in range(n):
        presum[i + 1] = presum[i] + w[i]
     i range(n) range n presum[i + 1] = presum[i] + w[i] presum[i + 1] presum i + 1 i 1 presum[i] + w[i] presum[i] presum i w[i] w i if n <= k:
        print(max(w))
        return
     n <= k n k print(max(w)) print max(w) max w return ok = 100000 * 10000 ok 100000 * 10000 100000 10000 ng = 0 ng 0 while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
     abs(ok - ng) > 1 abs(ok - ng) abs ok - ng ok ng 1 mid = (ok + ng) // 2 mid (ok + ng) // 2 ok + ng ok ng 2 if check(mid):
            ok = mid
        else:
            ng = mid
     check(mid) check mid ok = mid ok mid ng = mid ng mid print(ok) print ok resolve() resolve def resolve():
    global n, k, w, presum
    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    presum = [0 for _ in range(n + 1)]
    for i in range(n):
        presum[i + 1] = presum[i] + w[i]
    if n <= k:
        print(max(w))
        return
    ok = 100000 * 10000
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok) def resolve():
    global n, k, w, presum
    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    presum = [0 for _ in range(n + 1)]
    for i in range(n):
        presum[i + 1] = presum[i] + w[i]
    if n <= k:
        print(max(w))
        return
    ok = 100000 * 10000
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok) resolve def check(m):
    global n, k, w, presum
    s = 0
    for j in range(k):
        ok = s
        ng = n + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
        s = ok
    if s == n:
        return True
    else:
        return False def check(m):
    global n, k, w, presum
    s = 0
    for j in range(k):
        ok = s
        ng = n + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
        s = ok
    if s == n:
        return True
    else:
        return False check
def check(m):
    global n, k, w, presum
    s = 0
    for j in range(k):
        ok = s
        ng = n + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if presum[mid] - presum[s] <= m:
                ok = mid
            else:
                ng = mid
        s = ok
    if s == n:
        return True
    else:
        return False


def resolve():
    global n, k, w, presum
    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    presum = [0 for _ in range(n + 1)]
    for i in range(n):
        presum[i + 1] = presum[i] + w[i]
    if n <= k:
        print(max(w))
        return
    ok = 100000 * 10000
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


resolve()

