def check(P):
    global w, k
    t=1
    wt=0
    for wi in w:
        if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
        if t>k:
            return False
    return True

def search(l, r):
    if r-l==1:
        return r
    else:
        m=(l+r)//2
        if not check(m):
            return search(m,r)
        else:
            return search(l,m)

n,k=map(int,input().split())
w=[]
for i in range(n):
    w.append(int(input()))
S=sum(w);M=max(w)
#print(S,M)
P0=M-1
#print(P0)

print(search(M-1,S)) def check(P):
    global w, k
    t=1
    wt=0
    for wi in w:
        if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
        if t>k:
            return False
    return True check global w, k t=1 t 1 wt=0 wt 0 for wi in w:
        if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
        if t>k:
            return False
     wi w if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
         wt+wi>P wt+wi wt wi P wt=wi wt wi t+=1 t 1 wt+=wi wt wi if t>k:
            return False
     t>k t k return False False return True True P P def search(l, r):
    if r-l==1:
        return r
    else:
        m=(l+r)//2
        if not check(m):
            return search(m,r)
        else:
            return search(l,m) search if r-l==1:
        return r
    else:
        m=(l+r)//2
        if not check(m):
            return search(m,r)
        else:
            return search(l,m) r-l==1 r-l r l 1 return r r m=(l+r)//2 m (l+r)//2 l+r l r 2 if not check(m):
            return search(m,r)
        else:
            return search(l,m) not check(m) check(m) check m return search(m,r) search(m,r) search m r return search(l,m) search(l,m) search l m l l r r n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w=[] w [] for i in range(n):
    w.append(int(input())) i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input S=sum(w) S sum(w) sum w M=max(w) M max(w) max w P0=M-1 P0 M-1 M 1 print(search(M-1,S)) print search(M-1,S) search M-1 M 1 S n,k=map(int,input().split()) map(int,input().split()) n P0=M-1 M-1 P0 S=sum(w) sum(w) S k=map(int,input().split()) map(int,input().split()) k def search(l, r):
    if r-l==1:
        return r
    else:
        m=(l+r)//2
        if not check(m):
            return search(m,r)
        else:
            return search(l,m) def search(l, r):
    if r-l==1:
        return r
    else:
        m=(l+r)//2
        if not check(m):
            return search(m,r)
        else:
            return search(l,m) search def check(P):
    global w, k
    t=1
    wt=0
    for wi in w:
        if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
        if t>k:
            return False
    return True def check(P):
    global w, k
    t=1
    wt=0
    for wi in w:
        if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
        if t>k:
            return False
    return True check M=max(w) max(w) M w=[] [] w
def check(P):
    global w, k
    t=1
    wt=0
    for wi in w:
        if wt+wi>P:
            wt=wi
            t+=1
        else:
            wt+=wi
        if t>k:
            return False
    return True

def search(l, r):
    if r-l==1:
        return r
    else:
        m=(l+r)//2
        if not check(m):
            return search(m,r)
        else:
            return search(l,m)

n,k=map(int,input().split())
w=[]
for i in range(n):
    w.append(int(input()))
S=sum(w);M=max(w)
#print(S,M)
P0=M-1
#print(P0)

print(search(M-1,S))
