n, k = map(int,input().split())
ws = []
for _ in range(n):
    t = int(input())
    ws.append(t)

def check(m):
    need = 1
    sm = 0
    for w in ws:
        if w > m:
            return False
        if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
    return need <= k

lw = 0
hi = 10**10
ans = hi
while lw <= hi:
    mid = (lw + hi) // 2
    if check(mid):
        ans = mid
        hi = mid - 1
    else:
        lw = mid + 1

print(ans)

 n, k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k ws = [] ws [] for _ in range(n):
    t = int(input())
    ws.append(t) _ range(n) range n t = int(input()) t int(input()) int input() input ws.append(t) ws.append ws append t def check(m):
    need = 1
    sm = 0
    for w in ws:
        if w > m:
            return False
        if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
    return need <= k check need = 1 need 1 sm = 0 sm 0 for w in ws:
        if w > m:
            return False
        if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
     w ws if w > m:
            return False
         w > m w m return False False if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
     sm + w > m sm + w sm w m need += 1 need 1 sm = w sm w sm += w sm w return need <= k need <= k need k m m lw = 0 lw 0 hi = 10**10 hi 10**10 10 10 ans = hi ans hi while lw <= hi:
    mid = (lw + hi) // 2
    if check(mid):
        ans = mid
        hi = mid - 1
    else:
        lw = mid + 1 lw <= hi lw hi mid = (lw + hi) // 2 mid (lw + hi) // 2 lw + hi lw hi 2 if check(mid):
        ans = mid
        hi = mid - 1
    else:
        lw = mid + 1 check(mid) check mid ans = mid ans mid hi = mid - 1 hi mid - 1 mid 1 lw = mid + 1 lw mid + 1 mid 1 print(ans) print ans n, k = map(int,input().split()) map(int,input().split()) n ans = mid mid ans t = int(input()) int(input()) t k = map(int,input().split()) map(int,input().split()) k hi = 10**10 10**10 hi ans = hi hi ans mid = (lw + hi) // 2 (lw + hi) // 2 mid lw = mid + 1 mid + 1 lw def check(m):
    need = 1
    sm = 0
    for w in ws:
        if w > m:
            return False
        if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
    return need <= k def check(m):
    need = 1
    sm = 0
    for w in ws:
        if w > m:
            return False
        if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
    return need <= k check lw = 0 0 lw ws = [] [] ws hi = mid - 1 mid - 1 hi
n, k = map(int,input().split())
ws = []
for _ in range(n):
    t = int(input())
    ws.append(t)

def check(m):
    need = 1
    sm = 0
    for w in ws:
        if w > m:
            return False
        if sm + w > m:
            need += 1
            sm = w
        else:
            sm += w
    return need <= k

lw = 0
hi = 10**10
ans = hi
while lw <= hi:
    mid = (lw + hi) // 2
    if check(mid):
        ans = mid
        hi = mid - 1
    else:
        lw = mid + 1

print(ans)


