import sys
import math

def is_capable(n, k, w, P):
    track = 0
    cnt = 0
    i = 0

    while cnt < k:
        if i == n:
            return i

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

    return i
    pass

# ??\?????¨
n, k = map(int, sys.stdin.readline().split())
w = []
for i in range(n):
    w.append(int(sys.stdin.readline().strip()))

'''
print(n,k)
print(w)
'''

# ????????¨

if k == 1:
    ans = sum(w)
    print(ans)
elif n == 1:
    ans = w[0]
    print(ans)
else:
    max_p = sum(w)
    min_p = math.ceil(max_p / k) - 1

    # print(max_p, min_p)
    # sys.exit(0)
    
    bottom = min_p
    top = max_p

    while top - bottom > 1:
        mid = (bottom + top) // 2

        if is_capable(n, k, w, mid) == n:
            top = mid
        else:
            bottom = mid

    print(top) import sys sys import math math def is_capable(n, k, w, P):
    track = 0
    cnt = 0
    i = 0

    while cnt < k:
        if i == n:
            return i

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

    return i
    pass

# ??\?????¨ is_capable track = 0 track 0 cnt = 0 cnt 0 i = 0 i 0 while cnt < k:
        if i == n:
            return i

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

     cnt < k cnt k if i == n:
            return i

         i == n i n return i i if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

     track + w[i] > P track + w[i] track w[i] w i P track = 0 track 0 cnt += 1 cnt 1 track += w[i] track w[i] w i i += 1 i 1 return i i n n k k w w P P n, k = map(int, sys.stdin.readline().split()) n map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split k w = [] w [] for i in range(n):
    w.append(int(sys.stdin.readline().strip())) i range(n) range n w.append(int(sys.stdin.readline().strip())) w.append w append int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip '''
print(n,k)
print(w)
''' if k == 1:
    ans = sum(w)
    print(ans)
elif n == 1:
    ans = w[0]
    print(ans)
else:
    max_p = sum(w)
    min_p = math.ceil(max_p / k) - 1

    # print(max_p, min_p)
    # sys.exit(0)
    
    bottom = min_p
    top = max_p

    while top - bottom > 1:
        mid = (bottom + top) // 2

        if is_capable(n, k, w, mid) == n:
            top = mid
        else:
            bottom = mid

    print(top) k == 1 k 1 ans = sum(w) ans sum(w) sum w print(ans) print ans elif n == 1:
    ans = w[0]
    print(ans) n == 1 n 1 ans = w[0] ans w[0] w 0 print(ans) print ans max_p = sum(w) max_p sum(w) sum w min_p = math.ceil(max_p / k) - 1 min_p math.ceil(max_p / k) - 1 math.ceil(max_p / k) math.ceil math ceil max_p / k max_p k 1 bottom = min_p bottom min_p top = max_p top max_p while top - bottom > 1:
        mid = (bottom + top) // 2

        if is_capable(n, k, w, mid) == n:
            top = mid
        else:
            bottom = mid

     top - bottom > 1 top - bottom top bottom 1 mid = (bottom + top) // 2 mid (bottom + top) // 2 bottom + top bottom top 2 if is_capable(n, k, w, mid) == n:
            top = mid
        else:
            bottom = mid

     is_capable(n, k, w, mid) == n is_capable(n, k, w, mid) is_capable n k w mid n top = mid top mid bottom = mid bottom mid print(top) print top bottom = min_p min_p bottom bottom = mid mid bottom mid = (bottom + top) // 2 (bottom + top) // 2 mid k = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) k max_p = sum(w) sum(w) max_p w = [] [] w ans = sum(w) sum(w) ans n, k = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) n top = max_p max_p top ans = w[0] w[0] ans min_p = math.ceil(max_p / k) - 1 math.ceil(max_p / k) - 1 min_p def is_capable(n, k, w, P):
    track = 0
    cnt = 0
    i = 0

    while cnt < k:
        if i == n:
            return i

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

    return i
    pass

# ??\?????¨ def is_capable(n, k, w, P):
    track = 0
    cnt = 0
    i = 0

    while cnt < k:
        if i == n:
            return i

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

    return i
    pass

# ??\?????¨ is_capable top = mid mid top
import sys
import math

def is_capable(n, k, w, P):
    track = 0
    cnt = 0
    i = 0

    while cnt < k:
        if i == n:
            return i

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

    return i
    pass

# ??\?????¨
n, k = map(int, sys.stdin.readline().split())
w = []
for i in range(n):
    w.append(int(sys.stdin.readline().strip()))

'''
print(n,k)
print(w)
'''

# ????????¨

if k == 1:
    ans = sum(w)
    print(ans)
elif n == 1:
    ans = w[0]
    print(ans)
else:
    max_p = sum(w)
    min_p = math.ceil(max_p / k) - 1

    # print(max_p, min_p)
    # sys.exit(0)
    
    bottom = min_p
    top = max_p

    while top - bottom > 1:
        mid = (bottom + top) // 2

        if is_capable(n, k, w, mid) == n:
            top = mid
        else:
            bottom = mid

    print(top)