import sys
def input():
    return sys.stdin.readline()[:-1]
    
n,k = map(int, input().split())
w = [int(input()) for i in range(n)]

def get_v(n,k,w,P):
    c = 0
    val = 0
    for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
    return 1

left = max(w)
right = sum(w)
while True:
    P = (left + right)//2
    ret = get_v(n,k,w,P)
    if ret:
        right = P
    else:
        left = P + 1
    if left == right:
        break
print(left) import sys sys def input():
    return sys.stdin.readline()[:-1]
     input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 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 get_v(n,k,w,P):
    c = 0
    val = 0
    for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
    return 1 get_v c = 0 c 0 val = 0 val 0 for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
     i w val += i val i if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
     val > P val P c += 1 c 1 val = i val i if c >= k:
                return 0
     c >= k c k return 0 0 return 1 1 n n k k w w P P left = max(w) left max(w) max w right = sum(w) right sum(w) sum w while True:
    P = (left + right)//2
    ret = get_v(n,k,w,P)
    if ret:
        right = P
    else:
        left = P + 1
    if left == right:
        break True P = (left + right)//2 P (left + right)//2 left + right left right 2 ret = get_v(n,k,w,P) ret get_v(n,k,w,P) get_v n k w P if ret:
        right = P
    else:
        left = P + 1
     ret right = P right P left = P + 1 left P + 1 P 1 if left == right:
        break left == right left right break print(left) print left right = sum(w) sum(w) right k = map(int, input().split()) map(int, input().split()) k P = (left + right)//2 (left + right)//2 P left = P + 1 P + 1 left right = P P right def get_v(n,k,w,P):
    c = 0
    val = 0
    for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
    return 1 def get_v(n,k,w,P):
    c = 0
    val = 0
    for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
    return 1 get_v def input():
    return sys.stdin.readline()[:-1]
     def input():
    return sys.stdin.readline()[:-1]
     input w = [int(input()) for i in range(n)] [int(input()) for i in range(n)] w ret = get_v(n,k,w,P) get_v(n,k,w,P) ret left = max(w) max(w) left n,k = map(int, input().split()) map(int, input().split()) n
import sys
def input():
    return sys.stdin.readline()[:-1]
    
n,k = map(int, input().split())
w = [int(input()) for i in range(n)]

def get_v(n,k,w,P):
    c = 0
    val = 0
    for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
    return 1

left = max(w)
right = sum(w)
while True:
    P = (left + right)//2
    ret = get_v(n,k,w,P)
    if ret:
        right = P
    else:
        left = P + 1
    if left == right:
        break
print(left)
