N,K = map(int, raw_input().split())
W = [int(raw_input()) for _ in range(N)]

if N == 1:
    print W[0]
    exit()

def check(p):
    k = 1
    wt = 0
    for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
    return k <= K

left = min(W)
right = sum(W)
mid = 0
while left < right:
    #print left, right
    mid = int((left + right) / 2)
    #print mid,
    if check(mid):
        right = mid
    else:
        left = mid + 1

print left
 N,K = map(int, raw_input().split()) N map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split K int(raw_input()) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) int(raw_input()) int raw_input() raw_input W = [int(raw_input()) for _ in range(N)] W [int(raw_input()) for _ in range(N)] if N == 1:
    print W[0]
    exit() N == 1 N 1 print W[0] W 0 exit() exit def check(p):
    k = 1
    wt = 0
    for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
    return k <= K check k = 1 k 1 wt = 0 wt 0 for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
     w W if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
     wt + w <= mid wt + w wt w mid wt += w wt w if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
     w <= mid w mid wt = w wt w k += 1 k 1 return False False return k <= K k <= K k K p p left = min(W) left min(W) min W right = sum(W) right sum(W) sum W mid = 0 mid 0 while left < right:
    #print left, right
    mid = int((left + right) / 2)
    #print mid,
    if check(mid):
        right = mid
    else:
        left = mid + 1 left < right left right mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 if check(mid):
        right = mid
    else:
        left = mid + 1 check(mid) check mid right = mid right mid left = mid + 1 left mid + 1 mid 1 print def check(p):
    k = 1
    wt = 0
    for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
    return k <= K def check(p):
    k = 1
    wt = 0
    for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
    return k <= K check right = mid mid right N,K = map(int, raw_input().split()) map(int, raw_input().split()) N right = sum(W) sum(W) right mid = int((left + right) / 2) int((left + right) / 2) mid K = map(int, raw_input().split()) map(int, raw_input().split()) K W = [int(raw_input()) for _ in range(N)] [int(raw_input()) for _ in range(N)] W left = mid + 1 mid + 1 left left = min(W) min(W) left mid = 0 0 mid
N,K = map(int, raw_input().split())
W = [int(raw_input()) for _ in range(N)]

if N == 1:
    print W[0]
    exit()

def check(p):
    k = 1
    wt = 0
    for w in W:
        #print wt,
        if wt + w <= mid:
            wt += w
        else:
            if w <= mid:
                wt = w
                k += 1
            else:
                #print "error"
                return False
    #print k
    return k <= K

left = min(W)
right = sum(W)
mid = 0
while left < right:
    #print left, right
    mid = int((left + right) / 2)
    #print mid,
    if check(mid):
        right = mid
    else:
        left = mid + 1

print left

