import sys
import math

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

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

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

    return False
    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)

    capable = {min_p:False, max_p:True}

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

    while bottom < top:
        mid = (bottom + top) // 2

        if mid not in capable:
            capable[mid] = is_capable(n, k, w, mid)

        if capable[mid] == True:
            if (mid - 1) not in capable:
                capable[mid - 1] = is_capable(n, k, w, mid - 1)

            if capable[mid - 1] == False:
                ans = mid
                break
            else:
                top = mid
        elif capable[mid] == False:
            if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

            if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

    print(ans)
    # print(capable) 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 True

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

    return False
    pass

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

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

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

         i == n i n return True True 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 False False 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)

    capable = {min_p:False, max_p:True}

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

    while bottom < top:
        mid = (bottom + top) // 2

        if mid not in capable:
            capable[mid] = is_capable(n, k, w, mid)

        if capable[mid] == True:
            if (mid - 1) not in capable:
                capable[mid - 1] = is_capable(n, k, w, mid - 1)

            if capable[mid - 1] == False:
                ans = mid
                break
            else:
                top = mid
        elif capable[mid] == False:
            if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

            if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

    print(ans)
    # print(capable) 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 capable = {min_p:False, max_p:True} capable {min_p:False, max_p:True} min_p min_p False max_p max_p True bottom = min_p bottom min_p top = max_p top max_p while bottom < top:
        mid = (bottom + top) // 2

        if mid not in capable:
            capable[mid] = is_capable(n, k, w, mid)

        if capable[mid] == True:
            if (mid - 1) not in capable:
                capable[mid - 1] = is_capable(n, k, w, mid - 1)

            if capable[mid - 1] == False:
                ans = mid
                break
            else:
                top = mid
        elif capable[mid] == False:
            if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

            if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

     bottom < top bottom top mid = (bottom + top) // 2 mid (bottom + top) // 2 bottom + top bottom top 2 if mid not in capable:
            capable[mid] = is_capable(n, k, w, mid)

         mid not in capable mid capable capable[mid] = is_capable(n, k, w, mid) capable[mid] capable mid is_capable(n, k, w, mid) is_capable n k w mid if capable[mid] == True:
            if (mid - 1) not in capable:
                capable[mid - 1] = is_capable(n, k, w, mid - 1)

            if capable[mid - 1] == False:
                ans = mid
                break
            else:
                top = mid
        elif capable[mid] == False:
            if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

            if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

     capable[mid] == True capable[mid] capable mid True if (mid - 1) not in capable:
                capable[mid - 1] = is_capable(n, k, w, mid - 1)

             (mid - 1) not in capable mid - 1 mid 1 capable capable[mid - 1] = is_capable(n, k, w, mid - 1) capable[mid - 1] capable mid - 1 mid 1 is_capable(n, k, w, mid - 1) is_capable n k w mid - 1 mid 1 if capable[mid - 1] == False:
                ans = mid
                break
            else:
                top = mid
         capable[mid - 1] == False capable[mid - 1] capable mid - 1 mid 1 False ans = mid ans mid break top = mid top mid elif capable[mid] == False:
            if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

            if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

     capable[mid] == False capable[mid] capable mid False if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

             (mid + 1) not in capable mid + 1 mid 1 capable capable[mid + 1] = is_capable(n, k, w, mid + 1) capable[mid + 1] capable mid + 1 mid 1 is_capable(n, k, w, mid + 1) is_capable n k w mid + 1 mid 1 if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

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

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

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

    return False
    pass

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

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

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

    return False
    pass

# ??\?????¨ is_capable min_p = math.ceil(max_p / k) - 1 math.ceil(max_p / k) - 1 min_p
import sys
import math

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

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

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

    return False
    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)

    capable = {min_p:False, max_p:True}

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

    while bottom < top:
        mid = (bottom + top) // 2

        if mid not in capable:
            capable[mid] = is_capable(n, k, w, mid)

        if capable[mid] == True:
            if (mid - 1) not in capable:
                capable[mid - 1] = is_capable(n, k, w, mid - 1)

            if capable[mid - 1] == False:
                ans = mid
                break
            else:
                top = mid
        elif capable[mid] == False:
            if (mid + 1) not in capable:
                capable[mid + 1] = is_capable(n, k, w, mid + 1)

            if capable[mid + 1] == True:
                ans = mid + 1
                break
            else:
                bottom = mid + 1

    print(ans)
    # print(capable)