def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True

num, track = [int(x) for x in input().split()]
hoge_l = list()
for _ in range(num):
    hoge_l.append(int(input()))
left = 0
right = 100000 * 10000

while left < right :
    mid = (right + left) // 2
    if imas(hoge_l, mid, track):
        right = mid 
    else:
        left = mid + 1
        
max_num = max(hoge_l)
if max_num > right:
    right = max_num
print (right) def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True imas s_weights = 0 s_weights 0 now_track = 1 now_track 1 for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
     val hoge_l s_weights += val s_weights val if s_weights > p:
            s_weights = val
            now_track += 1
         s_weights > p s_weights p s_weights = val s_weights val now_track += 1 now_track 1 if now_track > track:
            return False
     now_track > track now_track track return False False return True True hoge_l hoge_l p p track track int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x num, track = [int(x) for x in input().split()] num [int(x) for x in input().split()] track hoge_l = list() hoge_l list() list for _ in range(num):
    hoge_l.append(int(input())) _ range(num) range num hoge_l.append(int(input())) hoge_l.append hoge_l append int(input()) int input() input left = 0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 while left < right :
    mid = (right + left) // 2
    if imas(hoge_l, mid, track):
        right = mid 
    else:
        left = mid + 1
         left < right left right mid = (right + left) // 2 mid (right + left) // 2 right + left right left 2 if imas(hoge_l, mid, track):
        right = mid 
    else:
        left = mid + 1
         imas(hoge_l, mid, track) imas hoge_l mid track right = mid right mid left = mid + 1 left mid + 1 mid 1 max_num = max(hoge_l) max_num max(hoge_l) max hoge_l if max_num > right:
    right = max_num max_num > right max_num right right = max_num right max_num print (right) print right left = 0 0 left track = [int(x) for x in input().split()] [int(x) for x in input().split()] track max_num = max(hoge_l) max(hoge_l) max_num left = mid + 1 mid + 1 left num, track = [int(x) for x in input().split()] [int(x) for x in input().split()] num right = 100000 * 10000 100000 * 10000 right right = mid mid right right = max_num max_num right def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True imas mid = (right + left) // 2 (right + left) // 2 mid hoge_l = list() list() hoge_l
def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True

num, track = [int(x) for x in input().split()]
hoge_l = list()
for _ in range(num):
    hoge_l.append(int(input()))
left = 0
right = 100000 * 10000

while left < right :
    mid = (right + left) // 2
    if imas(hoge_l, mid, track):
        right = mid 
    else:
        left = mid + 1
        
max_num = max(hoge_l)
if max_num > right:
    right = max_num
print (right)
