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

def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(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 i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input w = [int(input()) for i in range(n)] w [int(input()) for i in range(n)] def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left binarySearch mid = 0 mid 0 while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
     right > left right left mid = int(left + (right - left)//2) mid int(left + (right - left)//2) int left + (right - left)//2 left (right - left)//2 right - left right left 2 if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
     check(mid,w,k) check mid w k right = mid right mid left = mid + 1 left mid + 1 mid 1 return left left left left right right def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True check k_tmp = 1 k_tmp 1 w_tmp = 0 w_tmp 0 for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
     w_i w w_tmp += w_i w_tmp w_i if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
     w_tmp > p w_tmp p w_tmp = w_i w_tmp w_i k_tmp += 1 k_tmp 1 if k_tmp > k:
                return False
     k_tmp > k k_tmp k return False False return True True p p w w k k print(binarySearch(max(w),sum(w))) print binarySearch(max(w),sum(w)) binarySearch max(w) max w sum(w) sum w w = [int(input()) for i in range(n)] [int(input()) for i in range(n)] w def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left binarySearch n,k = map(int,input().split()) map(int,input().split()) n k = map(int,input().split()) map(int,input().split()) k def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True check
n,k = map(int,input().split())
w = [int(input()) for i in range(n)]

def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))