import sys
n,k = map(int,input().split())
w = list(map(int,sys.stdin.readlines()))

def binarysearch(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
    return left

def simulate(prb,wei,dai):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
    return True

print(binarysearch(max(w), sum(w))) import sys sys n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w = list(map(int,sys.stdin.readlines())) w list(map(int,sys.stdin.readlines())) list map(int,sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines def binarysearch(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
    return left binarysearch left = start left start right = end right end middle = 0 middle 0 while left < right:
        middle = (left + right)//2
        if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
     left < right left right middle = (left + right)//2 middle (left + right)//2 left + right left right 2 if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
     simulate(middle,w,k) simulate middle w k right = middle right middle left = middle + 1 left middle + 1 middle 1 return left left start start end end def simulate(prb,wei,dai):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
    return True simulate count = 1 count 1 tmp = 0 tmp 0 for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
     j wei tmp += j tmp j if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
     tmp > prb tmp prb tmp = j tmp j count += 1 count 1 if count > dai:
                return False
     count > dai count dai return False False return True True prb prb wei wei dai dai print(binarysearch(max(w), sum(w))) print binarysearch(max(w), sum(w)) binarysearch max(w) max w sum(w) sum w def simulate(prb,wei,dai):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
    return True def simulate(prb,wei,dai):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
    return True simulate def binarysearch(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
    return left def binarysearch(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
    return left binarysearch k = map(int,input().split()) map(int,input().split()) k n,k = map(int,input().split()) map(int,input().split()) n w = list(map(int,sys.stdin.readlines())) list(map(int,sys.stdin.readlines())) w
import sys
n,k = map(int,input().split())
w = list(map(int,sys.stdin.readlines()))

def binarysearch(start,end):
    left = start
    right = end
    middle = 0
    while left < right:
        middle = (left + right)//2
        if simulate(middle,w,k):
            right = middle
        else:
            left = middle + 1
    return left

def simulate(prb,wei,dai):
    count = 1
    tmp = 0
    for j in wei:
        tmp += j
        if tmp > prb:
            tmp = j
            count += 1
            if count > dai:
                return False
    return True

print(binarysearch(max(w), sum(w)))