# def f(P):
#     """与えられたPのときに、運べる荷物の数vを返す関数"""
#     i = 0  # 荷物の番号
#     v = 0  # 運べる荷物の数
#     k = 0  # トラックの番号
#     current_weight = 0  # 現在のトラックの重さ
#     # current_v = 0  # 現在のトラックに積まれている荷物の数
#
#     while True:
#         # print(i, v, k)
#
#         if W[i] > P:
#             i += 1
#         else:
#             current_weight += W[i]
#
#             if current_weight > P:
#                 k += 1
#             elif current_weight == P:
#                 i += 1
#                 v += 1
#                 k += 1
#             else:  # current_weight < P:
#                 i += 1
#                 v += 1
#
#         if i == N or k == K:
#             break
#     return v

def f(P):
    i = 0
    for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

    return i


def solve_binary():
    left = 0
    right = max(W)  # ではない！これだとトラックが足りなくて積み切れない場合がある。
    right = 100000 * 10000

    while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

    return right


def solve_linear():
    p = 1
    while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1


N, K = map(int, input().split())
# W = list(map(int, input().split()))
W = [int(input()) for _ in range(N)]
# print(n, k, W)

# print(solve_linear())
print(solve_binary())
 def f(P):
    i = 0
    for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

    return i f i = 0 i 0 for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

     k range(K) range K current_weight = 0 current_weight 0 while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

     current_weight + W[i] <= P current_weight + W[i] current_weight W[i] W i P current_weight += W[i] current_weight W[i] W i i += 1 i 1 if i == N:
                return N

     i == N i N return N N return i i P P def solve_binary():
    left = 0
    right = max(W)  # ではない！これだとトラックが足りなくて積み切れない場合がある。
    right = 100000 * 10000

    while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

    return right solve_binary left = 0 left 0 right = max(W) right max(W) max W right = 100000 * 10000 right 100000 * 10000 100000 10000 while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

     (right - left) > 1 right - left right left 1 mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 mid_v = f(mid) mid_v f(mid) f mid if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

     mid_v >= N mid_v N right = mid right mid elif mid_v < N:
            left = mid

     mid_v < N mid_v N left = mid left mid return right right def solve_linear():
    p = 1
    while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1 solve_linear p = 1 p 1 while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1 True v = f(p) v f(p) f p if v == N:
            # print(p)
            return p

         v == N v N return p p p = p + 1 p p + 1 p 1 N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K int(input()) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) int(input()) int input() input W = [int(input()) for _ in range(N)] W [int(input()) for _ in range(N)] print(solve_binary()) print solve_binary() solve_binary def f(P):
    i = 0
    for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

    return i def f(P):
    i = 0
    for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

    return i f W = [int(input()) for _ in range(N)] [int(input()) for _ in range(N)] W K = map(int, input().split()) map(int, input().split()) K N, K = map(int, input().split()) map(int, input().split()) N def solve_binary():
    left = 0
    right = max(W)  # ではない！これだとトラックが足りなくて積み切れない場合がある。
    right = 100000 * 10000

    while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

    return right def solve_binary():
    left = 0
    right = max(W)  # ではない！これだとトラックが足りなくて積み切れない場合がある。
    right = 100000 * 10000

    while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

    return right solve_binary def solve_linear():
    p = 1
    while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1 def solve_linear():
    p = 1
    while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1 solve_linear
# def f(P):
#     """与えられたPのときに、運べる荷物の数vを返す関数"""
#     i = 0  # 荷物の番号
#     v = 0  # 運べる荷物の数
#     k = 0  # トラックの番号
#     current_weight = 0  # 現在のトラックの重さ
#     # current_v = 0  # 現在のトラックに積まれている荷物の数
#
#     while True:
#         # print(i, v, k)
#
#         if W[i] > P:
#             i += 1
#         else:
#             current_weight += W[i]
#
#             if current_weight > P:
#                 k += 1
#             elif current_weight == P:
#                 i += 1
#                 v += 1
#                 k += 1
#             else:  # current_weight < P:
#                 i += 1
#                 v += 1
#
#         if i == N or k == K:
#             break
#     return v

def f(P):
    i = 0
    for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

    return i


def solve_binary():
    left = 0
    right = max(W)  # ではない！これだとトラックが足りなくて積み切れない場合がある。
    right = 100000 * 10000

    while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

    return right


def solve_linear():
    p = 1
    while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1


N, K = map(int, input().split())
# W = list(map(int, input().split()))
W = [int(input()) for _ in range(N)]
# print(n, k, W)

# print(solve_linear())
print(solve_binary())

