# -*- coding: utf-8 -*-

import sys
import os


n, k = map(int, input().split())
#print(k, '??°??§????????????')

W = []
for i in range(n):
    W.append(int(input()))

def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index

P_min = 1
P_max = sum(W)
P_mid = None
while True:
    P_mid = (P_min + P_max) // 2
    loaded_num = check(P_mid)

    if loaded_num < n:
        # ????????????????????????
        P_min = P_mid + 1
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

    if P_max == P_min:
        break

# ??????
print(P_max) import sys sys import os os n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k W = [] W [] for i in range(n):
    W.append(int(input())) i range(n) range n W.append(int(input())) W.append W append int(input()) int input() input def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index check weight_index = 0 weight_index 0 for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
     i range(k) range k current_weight = 0 current_weight 0 while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
     current_weight + W[weight_index] <= P current_weight + W[weight_index] current_weight W[weight_index] W weight_index P current_weight += W[weight_index] current_weight W[weight_index] W weight_index weight_index += 1 weight_index 1 if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
     weight_index == len(W) weight_index len(W) len W return len(W) len(W) len W return weight_index weight_index P P P_min = 1 P_min 1 P_max = sum(W) P_max sum(W) sum W P_mid = None P_mid None while True:
    P_mid = (P_min + P_max) // 2
    loaded_num = check(P_mid)

    if loaded_num < n:
        # ????????????????????????
        P_min = P_mid + 1
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

    if P_max == P_min:
        break

# ?????? True P_mid = (P_min + P_max) // 2 P_mid (P_min + P_max) // 2 P_min + P_max P_min P_max 2 loaded_num = check(P_mid) loaded_num check(P_mid) check P_mid if loaded_num < n:
        # ????????????????????????
        P_min = P_mid + 1
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

     loaded_num < n loaded_num n P_min = P_mid + 1 P_min P_mid + 1 P_mid 1 P_max = P_mid P_max P_mid if P_max == P_min:
        break

# ?????? P_max == P_min P_max P_min break print(P_max) print P_max W = [] [] W P_max = sum(W) sum(W) P_max P_mid = (P_min + P_max) // 2 (P_min + P_max) // 2 P_mid P_max = P_mid P_mid P_max n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k P_min = P_mid + 1 P_mid + 1 P_min P_mid = None None P_mid def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index check loaded_num = check(P_mid) check(P_mid) loaded_num P_min = 1 1 P_min
# -*- coding: utf-8 -*-

import sys
import os


n, k = map(int, input().split())
#print(k, '??°??§????????????')

W = []
for i in range(n):
    W.append(int(input()))

def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index

P_min = 1
P_max = sum(W)
P_mid = None
while True:
    P_mid = (P_min + P_max) // 2
    loaded_num = check(P_mid)

    if loaded_num < n:
        # ????????????????????????
        P_min = P_mid + 1
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

    if P_max == P_min:
        break

# ??????
print(P_max)