#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
#??????????????????

def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p

def check(truck_num, carogs, target_load):
    
    cur_truck = 1
    cur_weight = 0
    for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
    return True

def solve(truck_num, cargs):

    max_load = sum(cargos)
    min_load = max(cargos)
    #print(min_load, max_load)
    while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
    return max_load

if __name__ == "__main__":
    line = input()
    truck_num = int(line.split(" ")[1])
    line_num = int(line.split(" ")[0])
    cargos = [int(input()) for i in range(line_num)]
    print(solve(truck_num,cargos)) def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p cal p = 0 p 0 for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
     i range(len(cargos) - truck_num + 1) range len(cargos) - truck_num + 1 len(cargos) - truck_num len(cargos) len cargos truck_num 1 if not i == 0 and p < sum(cargos[:i + 1]):
            continue
         not i == 0 and p < sum(cargos[:i + 1]) not i == 0 i == 0 i 0 p < sum(cargos[:i + 1]) p sum(cargos[:i + 1]) sum cargos[:i + 1] cargos :i + 1 i + 1 i 1 continue if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
     truck_num > 1 truck_num 1 r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:])) r max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:])) max sum(cargos[:i + 1]) sum cargos[:i + 1] cargos :i + 1 i + 1 i 1 cal(truck_num - 1, cargos[i + 1:]) cal truck_num - 1 truck_num 1 cargos[i + 1:] cargos i + 1: i + 1 i 1 if i == 0:
                p = r
            elif p > r:
                p = r
         i == 0 i 0 p = r p r elif p > r:
                p = r
         p > r p r p = r p r return sum(cargos) sum(cargos) sum cargos return p p truck_num truck_num cargos cargos def check(truck_num, carogs, target_load):
    
    cur_truck = 1
    cur_weight = 0
    for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
    return True check cur_truck = 1 cur_truck 1 cur_weight = 0 cur_weight 0 for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
     weight cargos cur_weight += weight cur_weight weight if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
     cur_weight > target_load cur_weight target_load cur_weight = weight cur_weight weight cur_truck += 1 cur_truck 1 if cur_truck > truck_num:
                return False
     cur_truck > truck_num cur_truck truck_num return False False return True True truck_num truck_num carogs carogs target_load target_load def solve(truck_num, cargs):

    max_load = sum(cargos)
    min_load = max(cargos)
    #print(min_load, max_load)
    while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
    return max_load solve max_load = sum(cargos) max_load sum(cargos) sum cargos min_load = max(cargos) min_load max(cargos) max cargos while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
     min_load < max_load min_load max_load target_load = int((min_load + max_load)/2) target_load int((min_load + max_load)/2) int (min_load + max_load)/2 min_load + max_load min_load max_load 2 if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
     check(truck_num, cargos, target_load) check truck_num cargos target_load max_load = target_load max_load target_load min_load = target_load + 1 min_load target_load + 1 target_load 1 return max_load max_load truck_num truck_num cargs cargs if __name__ == "__main__":
    line = input()
    truck_num = int(line.split(" ")[1])
    line_num = int(line.split(" ")[0])
    cargos = [int(input()) for i in range(line_num)]
    print(solve(truck_num,cargos)) __name__ == "__main__" __name__ "__main__" line = input() line input() input truck_num = int(line.split(" ")[1]) truck_num int(line.split(" ")[1]) int line.split(" ")[1] line.split(" ") line.split line split " " 1 line_num = int(line.split(" ")[0]) line_num int(line.split(" ")[0]) int line.split(" ")[0] line.split(" ") line.split line split " " 0 int(input()) for i in range(line_num) for i in range(line_num) i range(line_num) range line_num for i in range(line_num) int(input()) int input() input cargos = [int(input()) for i in range(line_num)] cargos [int(input()) for i in range(line_num)] print(solve(truck_num,cargos)) print solve(truck_num,cargos) solve truck_num cargos def check(truck_num, carogs, target_load):
    
    cur_truck = 1
    cur_weight = 0
    for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
    return True def check(truck_num, carogs, target_load):
    
    cur_truck = 1
    cur_weight = 0
    for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
    return True check def solve(truck_num, cargs):

    max_load = sum(cargos)
    min_load = max(cargos)
    #print(min_load, max_load)
    while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
    return max_load def solve(truck_num, cargs):

    max_load = sum(cargos)
    min_load = max(cargos)
    #print(min_load, max_load)
    while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
    return max_load solve cargos = [int(input()) for i in range(line_num)] [int(input()) for i in range(line_num)] cargos def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p cal line_num = int(line.split(" ")[0]) int(line.split(" ")[0]) line_num line = input() input() line truck_num = int(line.split(" ")[1]) int(line.split(" ")[1]) truck_num
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
#??????????????????

def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p

def check(truck_num, carogs, target_load):
    
    cur_truck = 1
    cur_weight = 0
    for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
    return True

def solve(truck_num, cargs):

    max_load = sum(cargos)
    min_load = max(cargos)
    #print(min_load, max_load)
    while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
    return max_load

if __name__ == "__main__":
    line = input()
    truck_num = int(line.split(" ")[1])
    line_num = int(line.split(" ")[0])
    cargos = [int(input()) for i in range(line_num)]
    print(solve(truck_num,cargos))