#coding:utf-8
   
n, k = map(int, input().split())
backList = []
for i in range(n):
    backList.append(int(input()))

def capa(p,k):
    cnt = 0
    pcopy = p
    num = 0
    for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
    return cnt


p_min = 0
p_max = 100000 * 10000
def biSearch(p_min, p_max):
    p = p_max - p_min
    if p_max - p_min <= 1:
        return p_max
    if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
    v = capa(c,k)
    if v < n:
        p_min = c
    else:
        p_max = c

    return biSearch(p_min, p_max)
            

p = biSearch(p_min, p_max)
n_init = n
while n_init <= n:
    p -= 1
    n = capa(p,k)

print(p+1)
 n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k backList = [] backList [] for i in range(n):
    backList.append(int(input())) i range(n) range n backList.append(int(input())) backList.append backList append int(input()) int input() input def capa(p,k):
    cnt = 0
    pcopy = p
    num = 0
    for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
    return cnt capa cnt = 0 cnt 0 pcopy = p pcopy p num = 0 num 0 for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
     back backList if back > p:
            break
         back > p back p break if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
     back <= pcopy back pcopy pcopy -= back pcopy back cnt += 1 cnt 1 continue elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
     back > pcopy back pcopy if num == k-1:
                return cnt
             num == k-1 num k-1 k 1 return cnt cnt pcopy = p - back pcopy p - back p back cnt += 1 cnt 1 num += 1 num 1 return cnt cnt p p k k p_min = 0 p_min 0 p_max = 100000 * 10000 p_max 100000 * 10000 100000 10000 def biSearch(p_min, p_max):
    p = p_max - p_min
    if p_max - p_min <= 1:
        return p_max
    if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
    v = capa(c,k)
    if v < n:
        p_min = c
    else:
        p_max = c

    return biSearch(p_min, p_max)
             biSearch p = p_max - p_min p p_max - p_min p_max p_min if p_max - p_min <= 1:
        return p_max
     p_max - p_min <= 1 p_max - p_min p_max p_min 1 return p_max p_max if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
     p % 2 == 0 p % 2 p 2 0 c = p_min + int(p/2) c p_min + int(p/2) p_min int(p/2) int p/2 p 2 c = p_min + int((p+1)/2) c p_min + int((p+1)/2) p_min int((p+1)/2) int (p+1)/2 p+1 p 1 2 v = capa(c,k) v capa(c,k) capa c k if v < n:
        p_min = c
    else:
        p_max = c

     v < n v n p_min = c p_min c p_max = c p_max c return biSearch(p_min, p_max) biSearch(p_min, p_max) biSearch p_min p_max p_min p_min p_max p_max p = biSearch(p_min, p_max) p biSearch(p_min, p_max) biSearch p_min p_max n_init = n n_init n while n_init <= n:
    p -= 1
    n = capa(p,k) n_init <= n n_init n p -= 1 p 1 n = capa(p,k) n capa(p,k) capa p k print(p+1) print p+1 p 1 n_init = n n n_init p -= 1 1 p def capa(p,k):
    cnt = 0
    pcopy = p
    num = 0
    for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
    return cnt def capa(p,k):
    cnt = 0
    pcopy = p
    num = 0
    for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
    return cnt capa n = capa(p,k) capa(p,k) n n, k = map(int, input().split()) map(int, input().split()) n p_min = 0 0 p_min backList = [] [] backList p_max = 100000 * 10000 100000 * 10000 p_max p = biSearch(p_min, p_max) biSearch(p_min, p_max) p k = map(int, input().split()) map(int, input().split()) k def biSearch(p_min, p_max):
    p = p_max - p_min
    if p_max - p_min <= 1:
        return p_max
    if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
    v = capa(c,k)
    if v < n:
        p_min = c
    else:
        p_max = c

    return biSearch(p_min, p_max)
             def biSearch(p_min, p_max):
    p = p_max - p_min
    if p_max - p_min <= 1:
        return p_max
    if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
    v = capa(c,k)
    if v < n:
        p_min = c
    else:
        p_max = c

    return biSearch(p_min, p_max)
             biSearch
#coding:utf-8
   
n, k = map(int, input().split())
backList = []
for i in range(n):
    backList.append(int(input()))

def capa(p,k):
    cnt = 0
    pcopy = p
    num = 0
    for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
    return cnt


p_min = 0
p_max = 100000 * 10000
def biSearch(p_min, p_max):
    p = p_max - p_min
    if p_max - p_min <= 1:
        return p_max
    if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
    v = capa(c,k)
    if v < n:
        p_min = c
    else:
        p_max = c

    return biSearch(p_min, p_max)
            

p = biSearch(p_min, p_max)
n_init = n
while n_init <= n:
    p -= 1
    n = capa(p,k)

print(p+1)

