#coding:utf-8
#1_4_D
def is_carriable(w_lim, trucks, loads):
    """ Check whether w_lim(maximum carrying capacity) is possible or not """
    i = 0
    while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
    return False

n, trucks = map(int, input().split())
loads = [int(input()) for i in range(n)]

left = max(loads)
right = sum(loads) + 1

while right - left > 1:
    mid = (left + right) // 2
    if is_carriable(mid, trucks, loads):
        ans = mid
        right = mid
    else:
        left = mid

if is_carriable(max(loads), trucks, loads):
    ans = max(loads)

print(ans) def is_carriable(w_lim, trucks, loads):
    """ Check whether w_lim(maximum carrying capacity) is possible or not """
    i = 0
    while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
    return False is_carriable """ Check whether w_lim(maximum carrying capacity) is possible or not """ i = 0 i 0 while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
     trucks > 0 trucks 0 w = 0 w 0 while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
         i < len(loads) i len(loads) len loads if w + loads[i] > w_lim:
                trucks -= 1
                break
             w + loads[i] > w_lim w + loads[i] w loads[i] loads i w_lim trucks -= 1 trucks 1 break w += loads[i] w loads[i] loads i i += 1 i 1 if i == len(loads):
            return True
     i == len(loads) i len(loads) len loads return True True return False False w_lim w_lim trucks trucks loads loads n, trucks = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split trucks int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input loads = [int(input()) for i in range(n)] loads [int(input()) for i in range(n)] left = max(loads) left max(loads) max loads right = sum(loads) + 1 right sum(loads) + 1 sum(loads) sum loads 1 while right - left > 1:
    mid = (left + right) // 2
    if is_carriable(mid, trucks, loads):
        ans = mid
        right = mid
    else:
        left = mid right - left > 1 right - left right left 1 mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if is_carriable(mid, trucks, loads):
        ans = mid
        right = mid
    else:
        left = mid is_carriable(mid, trucks, loads) is_carriable mid trucks loads ans = mid ans mid right = mid right mid left = mid left mid if is_carriable(max(loads), trucks, loads):
    ans = max(loads) is_carriable(max(loads), trucks, loads) is_carriable max(loads) max loads trucks loads ans = max(loads) ans max(loads) max loads print(ans) print ans ans = mid mid ans trucks = map(int, input().split()) map(int, input().split()) trucks mid = (left + right) // 2 (left + right) // 2 mid def is_carriable(w_lim, trucks, loads):
    """ Check whether w_lim(maximum carrying capacity) is possible or not """
    i = 0
    while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
    return False def is_carriable(w_lim, trucks, loads):
    """ Check whether w_lim(maximum carrying capacity) is possible or not """
    i = 0
    while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
    return False is_carriable right = sum(loads) + 1 sum(loads) + 1 right ans = max(loads) max(loads) ans right = mid mid right n, trucks = map(int, input().split()) map(int, input().split()) n loads = [int(input()) for i in range(n)] [int(input()) for i in range(n)] loads left = max(loads) max(loads) left left = mid mid left
#coding:utf-8
#1_4_D
def is_carriable(w_lim, trucks, loads):
    """ Check whether w_lim(maximum carrying capacity) is possible or not """
    i = 0
    while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
    return False

n, trucks = map(int, input().split())
loads = [int(input()) for i in range(n)]

left = max(loads)
right = sum(loads) + 1

while right - left > 1:
    mid = (left + right) // 2
    if is_carriable(mid, trucks, loads):
        ans = mid
        right = mid
    else:
        left = mid

if is_carriable(max(loads), trucks, loads):
    ans = max(loads)

print(ans)