def check(n,k,p,T):
    i = 0
    for j in range(k):
        s = 0
        while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
    return i


def solve(n,k,T):
    left =0
    right = 100000 * 10000
    mid = 0
    while (right -left > 1):
        mid = (left + right)//2
        v = check(n,k,mid,T)
        if (v >= n):
            right = mid
        else:
            left = mid
    return right

lis=[]
a = input()
(nn,kk)=list(map(int,a.split()))
for i in range(nn):
    lis.append(int(input()))
ans = solve(nn,kk,lis)
print(ans) def check(n,k,p,T):
    i = 0
    for j in range(k):
        s = 0
        while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
    return i check i = 0 i 0 for j in range(k):
        s = 0
        while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
     j range(k) range k s = 0 s 0 while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
     s+T[i] <= p s+T[i] s T[i] T i p s = s+T[i] s s+T[i] s T[i] T i i = i+1 i i+1 i 1 if (i==n):
                return n
     i==n i n return n n return i i n n k k p p T T def solve(n,k,T):
    left =0
    right = 100000 * 10000
    mid = 0
    while (right -left > 1):
        mid = (left + right)//2
        v = check(n,k,mid,T)
        if (v >= n):
            right = mid
        else:
            left = mid
    return right solve left =0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 mid = 0 mid 0 while (right -left > 1):
        mid = (left + right)//2
        v = check(n,k,mid,T)
        if (v >= n):
            right = mid
        else:
            left = mid
     right -left > 1 right -left right left 1 mid = (left + right)//2 mid (left + right)//2 left + right left right 2 v = check(n,k,mid,T) v check(n,k,mid,T) check n k mid T if (v >= n):
            right = mid
        else:
            left = mid
     v >= n v n right = mid right mid left = mid left mid return right right n n k k T T lis=[] lis [] a = input() a input() input (nn,kk)=list(map(int,a.split())) (nn,kk) nn kk list(map(int,a.split())) list map(int,a.split()) map int a.split() a.split a split for i in range(nn):
    lis.append(int(input())) i range(nn) range nn lis.append(int(input())) lis.append lis append int(input()) int input() input ans = solve(nn,kk,lis) ans solve(nn,kk,lis) solve nn kk lis print(ans) print ans a = input() input() a def solve(n,k,T):
    left =0
    right = 100000 * 10000
    mid = 0
    while (right -left > 1):
        mid = (left + right)//2
        v = check(n,k,mid,T)
        if (v >= n):
            right = mid
        else:
            left = mid
    return right def solve(n,k,T):
    left =0
    right = 100000 * 10000
    mid = 0
    while (right -left > 1):
        mid = (left + right)//2
        v = check(n,k,mid,T)
        if (v >= n):
            right = mid
        else:
            left = mid
    return right solve lis=[] [] lis ans = solve(nn,kk,lis) solve(nn,kk,lis) ans def check(n,k,p,T):
    i = 0
    for j in range(k):
        s = 0
        while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
    return i def check(n,k,p,T):
    i = 0
    for j in range(k):
        s = 0
        while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
    return i check
def check(n,k,p,T):
    i = 0
    for j in range(k):
        s = 0
        while(s+T[i] <= p):
            s = s+T[i]
            i = i+1
            if (i==n):
                return n
    return i


def solve(n,k,T):
    left =0
    right = 100000 * 10000
    mid = 0
    while (right -left > 1):
        mid = (left + right)//2
        v = check(n,k,mid,T)
        if (v >= n):
            right = mid
        else:
            left = mid
    return right

lis=[]
a = input()
(nn,kk)=list(map(int,a.split()))
for i in range(nn):
    lis.append(int(input()))
ans = solve(nn,kk,lis)
print(ans)