def is_ok(W, truck, middle):
    loaded = 0
    for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
    return False

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
    return ok

n, k = map(int,input().split())

w = [0]*n
for i in range(n):
    w[i] = int(input())

ans = meguru_bisect(-1,10**10+1)
print(ans) def is_ok(W, truck, middle):
    loaded = 0
    for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
    return False is_ok loaded = 0 loaded 0 for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
     t range(truck) range truck this_total = 0 this_total 0 while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
     this_total + W[loaded] <= middle this_total + W[loaded] this_total W[loaded] W loaded middle this_total += W[loaded] this_total W[loaded] W loaded loaded += 1 loaded 1 if loaded == len(W):
                return True
     loaded == len(W) loaded len(W) len W return True True return False False W W truck truck middle middle def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
    return ok meguru_bisect while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, 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 is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
     is_ok(w, k, mid) is_ok w k mid ok = mid ok mid ng = mid ng mid return ok ok ng ng ok ok n, k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w = [0]*n w [0]*n [0] 0 n for i in range(n):
    w[i] = int(input()) i range(n) range n w[i] = int(input()) w[i] w i int(input()) int input() input ans = meguru_bisect(-1,10**10+1) ans meguru_bisect(-1,10**10+1) meguru_bisect -1 10**10+1 10**10 10 10 1 print(ans) print ans def is_ok(W, truck, middle):
    loaded = 0
    for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
    return False def is_ok(W, truck, middle):
    loaded = 0
    for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
    return False is_ok n, k = map(int,input().split()) map(int,input().split()) n ans = meguru_bisect(-1,10**10+1) meguru_bisect(-1,10**10+1) ans def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
    return ok def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
    return ok meguru_bisect w = [0]*n [0]*n w k = map(int,input().split()) map(int,input().split()) k
def is_ok(W, truck, middle):
    loaded = 0
    for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
    return False

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
    return ok

n, k = map(int,input().split())

w = [0]*n
for i in range(n):
    w[i] = int(input())

ans = meguru_bisect(-1,10**10+1)
print(ans)
