n,k = map(int,input().split())
a = [int(input()) for s in range(n)]
pmax = sum(a)
pmin = pmax//k-1

def check(ptest):
    tk = 1
    p = 0
    global a,k,n
    i = 0
    while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
    return True

while (pmax-pmin) > 1:
    pmid = (pmax+pmin)//2
    if check(pmid):
        pmax = pmid
    else:
        pmin = pmid
print(pmax)

 n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k int(input()) for s in range(n) for s in range(n) s range(n) range n for s in range(n) int(input()) int input() input a = [int(input()) for s in range(n)] a [int(input()) for s in range(n)] pmax = sum(a) pmax sum(a) sum a pmin = pmax//k-1 pmin pmax//k-1 pmax//k pmax k 1 def check(ptest):
    tk = 1
    p = 0
    global a,k,n
    i = 0
    while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
    return True check tk = 1 tk 1 p = 0 p 0 global a,k,n i = 0 i 0 while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
     i < n i n p += a[i] p a[i] a i if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
         p <= ptest p ptest i += 1 i 1 tk += 1 tk 1 p = 0 p 0 if tk > k:
            return False
     tk > k tk k return False False return True True ptest ptest while (pmax-pmin) > 1:
    pmid = (pmax+pmin)//2
    if check(pmid):
        pmax = pmid
    else:
        pmin = pmid (pmax-pmin) > 1 pmax-pmin pmax pmin 1 pmid = (pmax+pmin)//2 pmid (pmax+pmin)//2 pmax+pmin pmax pmin 2 if check(pmid):
        pmax = pmid
    else:
        pmin = pmid check(pmid) check pmid pmax = pmid pmax pmid pmin = pmid pmin pmid print(pmax) print pmax pmid = (pmax+pmin)//2 (pmax+pmin)//2 pmid pmax = pmid pmid pmax n,k = map(int,input().split()) map(int,input().split()) n pmin = pmid pmid pmin pmax = sum(a) sum(a) pmax pmin = pmax//k-1 pmax//k-1 pmin k = map(int,input().split()) map(int,input().split()) k def check(ptest):
    tk = 1
    p = 0
    global a,k,n
    i = 0
    while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
    return True def check(ptest):
    tk = 1
    p = 0
    global a,k,n
    i = 0
    while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
    return True check a = [int(input()) for s in range(n)] [int(input()) for s in range(n)] a
n,k = map(int,input().split())
a = [int(input()) for s in range(n)]
pmax = sum(a)
pmin = pmax//k-1

def check(ptest):
    tk = 1
    p = 0
    global a,k,n
    i = 0
    while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
    return True

while (pmax-pmin) > 1:
    pmid = (pmax+pmin)//2
    if check(pmid):
        pmax = pmid
    else:
        pmin = pmid
print(pmax)


