def check_p(packages, n, trucks, max_p):
    i = 0
    for _ in range(trucks):
        sum = 0
        while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
    return i

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

left = 0
right = 10 ** 5 * 10 ** 4
while left + 1 < right:
    mid = (left + right) // 2
    num = check_p(packages, n, k, mid)
    if num < n:
        left = mid
    else:
        right = mid
print(right)
 def check_p(packages, n, trucks, max_p):
    i = 0
    for _ in range(trucks):
        sum = 0
        while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
    return i check_p i = 0 i 0 for _ in range(trucks):
        sum = 0
        while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
     _ range(trucks) range trucks sum = 0 sum 0 while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
     sum + packages[i] <= max_p sum + packages[i] sum packages[i] packages i max_p sum += packages[i] sum packages[i] packages i i += 1 i 1 if i == n:
                return i
     i == n i n return i i return i i packages packages n n trucks trucks max_p max_p n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k packages = [] packages [] for _ in range(n):
    packages.append(int(input())) _ range(n) range n packages.append(int(input())) packages.append packages append int(input()) int input() input left = 0 left 0 right = 10 ** 5 * 10 ** 4 right 10 ** 5 * 10 ** 4 10 ** 5 10 5 10 ** 4 10 4 while left + 1 < right:
    mid = (left + right) // 2
    num = check_p(packages, n, k, mid)
    if num < n:
        left = mid
    else:
        right = mid left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 num = check_p(packages, n, k, mid) num check_p(packages, n, k, mid) check_p packages n k mid if num < n:
        left = mid
    else:
        right = mid num < n num n left = mid left mid right = mid right mid print(right) print right right = 10 ** 5 * 10 ** 4 10 ** 5 * 10 ** 4 right mid = (left + right) // 2 (left + right) // 2 mid right = mid mid right left = 0 0 left def check_p(packages, n, trucks, max_p):
    i = 0
    for _ in range(trucks):
        sum = 0
        while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
    return i def check_p(packages, n, trucks, max_p):
    i = 0
    for _ in range(trucks):
        sum = 0
        while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
    return i check_p n, k = map(int, input().split()) map(int, input().split()) n packages = [] [] packages left = mid mid left k = map(int, input().split()) map(int, input().split()) k num = check_p(packages, n, k, mid) check_p(packages, n, k, mid) num
def check_p(packages, n, trucks, max_p):
    i = 0
    for _ in range(trucks):
        sum = 0
        while sum + packages[i] <= max_p:
            sum += packages[i]
            i += 1
            if i == n:
                return i
    return i

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

left = 0
right = 10 ** 5 * 10 ** 4
while left + 1 < right:
    mid = (left + right) // 2
    num = check_p(packages, n, k, mid)
    if num < n:
        left = mid
    else:
        right = mid
print(right)

