n,k = map(int, input().split())
w = [int(input()) for _ in range(n)]

def bs(left, right):
    mid = 0
    
    while left < right:
        mid = (left + right ) //2
        if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
    return mid

def check(v, wgt, num):
    cnt = 1
    tmp = 0
    for j in wgt:
        tmp += j
        if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
    return True
    
print(bs(max(w), sum(w))) 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)] def bs(left, right):
    mid = 0
    
    while left < right:
        mid = (left + right ) //2
        if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
    return mid bs mid = 0 mid 0 while left < right:
        mid = (left + right ) //2
        if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
     left < right left right mid = (left + right ) //2 mid (left + right ) //2 left + right left right 2 if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
     check(mid, w, k) check mid w k right = mid right mid mid += 1 mid 1 left = mid left mid return mid mid left left right right def check(v, wgt, num):
    cnt = 1
    tmp = 0
    for j in wgt:
        tmp += j
        if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
    return True
     check cnt = 1 cnt 1 tmp = 0 tmp 0 for j in wgt:
        tmp += j
        if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
     j wgt tmp += j tmp j if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
     tmp > v tmp v tmp = j tmp j cnt += 1 cnt 1 if cnt > num:
                return False
     cnt > num cnt num return False False return True True v v wgt wgt num num print(bs(max(w), sum(w))) print bs(max(w), sum(w)) bs max(w) max w sum(w) sum w w = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] w k = map(int, input().split()) map(int, input().split()) k def bs(left, right):
    mid = 0
    
    while left < right:
        mid = (left + right ) //2
        if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
    return mid def bs(left, right):
    mid = 0
    
    while left < right:
        mid = (left + right ) //2
        if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
    return mid bs n,k = map(int, input().split()) map(int, input().split()) n def check(v, wgt, num):
    cnt = 1
    tmp = 0
    for j in wgt:
        tmp += j
        if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
    return True
     def check(v, wgt, num):
    cnt = 1
    tmp = 0
    for j in wgt:
        tmp += j
        if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
    return True
     check
n,k = map(int, input().split())
w = [int(input()) for _ in range(n)]

def bs(left, right):
    mid = 0
    
    while left < right:
        mid = (left + right ) //2
        if check(mid, w, k):
            right = mid
        else:
            mid += 1
            left = mid
    return mid

def check(v, wgt, num):
    cnt = 1
    tmp = 0
    for j in wgt:
        tmp += j
        if tmp > v:
            tmp = j
            cnt += 1
            if cnt > num:
                return False
    return True
    
print(bs(max(w), sum(w)))