from sys import stdin

def solve_howmany_trucks(P):
    '''
    トラックの数がk、最大積載量がPのとき荷物を載せきれるかを判定する
    '''
    truck = 1
    temp_weight = 0
    for a,b in enumerate(w):
        if b > P:
            return False
        if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

    return True



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

w = [int(input()) for a in range(n)]

min_P = 10000*100000
left = 0
right = min_P
while left != right:
    middle = int((left+right)/2)
    if solve_howmany_trucks(middle):
        right = middle
    else:
        left = middle+1
print(left)
 from sys import stdin def solve_howmany_trucks(P):
    '''
    トラックの数がk、最大積載量がPのとき荷物を載せきれるかを判定する
    '''
    truck = 1
    temp_weight = 0
    for a,b in enumerate(w):
        if b > P:
            return False
        if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

    return True solve_howmany_trucks '''
    トラックの数がk、最大積載量がPのとき荷物を載せきれるかを判定する
    ''' truck = 1 truck 1 temp_weight = 0 temp_weight 0 for a,b in enumerate(w):
        if b > P:
            return False
        if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

     a b enumerate(w) enumerate w if b > P:
            return False
         b > P b P return False False if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

     temp_weight + b > P temp_weight + b temp_weight b P truck += 1 truck 1 if truck > k:
                return False
             truck > k truck k return False False temp_weight = b temp_weight b temp_weight += b temp_weight b return True True P P n,k = input().split() n input().split() ().split () input split k n = int(n) n int(n) int n k = int(k) k int(k) int k int(input()) for a in range(n) for a in range(n) a range(n) range n for a in range(n) int(input()) int input() input w = [int(input()) for a in range(n)] w [int(input()) for a in range(n)] min_P = 10000*100000 min_P 10000*100000 10000 100000 left = 0 left 0 right = min_P right min_P while left != right:
    middle = int((left+right)/2)
    if solve_howmany_trucks(middle):
        right = middle
    else:
        left = middle+1 left != right left right middle = int((left+right)/2) middle int((left+right)/2) int (left+right)/2 left+right left right 2 if solve_howmany_trucks(middle):
        right = middle
    else:
        left = middle+1 solve_howmany_trucks(middle) solve_howmany_trucks middle right = middle right middle left = middle+1 left middle+1 middle 1 print(left) print left k = input().split() input().split() k left = 0 0 left k = int(k) int(k) k def solve_howmany_trucks(P):
    '''
    トラックの数がk、最大積載量がPのとき荷物を載せきれるかを判定する
    '''
    truck = 1
    temp_weight = 0
    for a,b in enumerate(w):
        if b > P:
            return False
        if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

    return True def solve_howmany_trucks(P):
    '''
    トラックの数がk、最大積載量がPのとき荷物を載せきれるかを判定する
    '''
    truck = 1
    temp_weight = 0
    for a,b in enumerate(w):
        if b > P:
            return False
        if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

    return True solve_howmany_trucks n = int(n) int(n) n right = middle middle right n,k = input().split() input().split() n right = min_P min_P right min_P = 10000*100000 10000*100000 min_P w = [int(input()) for a in range(n)] [int(input()) for a in range(n)] w middle = int((left+right)/2) int((left+right)/2) middle left = middle+1 middle+1 left
from sys import stdin

def solve_howmany_trucks(P):
    '''
    トラックの数がk、最大積載量がPのとき荷物を載せきれるかを判定する
    '''
    truck = 1
    temp_weight = 0
    for a,b in enumerate(w):
        if b > P:
            return False
        if temp_weight + b > P:
            # print(f"P = {P} truck No {truck} temp_weight {temp_weight+b}")
            truck += 1
            if truck > k:
                return False
            temp_weight = b
        else:
            temp_weight += b

    return True



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

w = [int(input()) for a in range(n)]

min_P = 10000*100000
left = 0
right = min_P
while left != right:
    middle = int((left+right)/2)
    if solve_howmany_trucks(middle):
        right = middle
    else:
        left = middle+1
print(left)

