# coding: utf-8

n, k = map(int, input().rstrip().split())
w = [0 for _ in range(n)]
for i in range(n):
    w[i] = int(input())
    
# from random import randint
# n = 100000
# k = 10000
# w = [0 for _ in range(n)]
# for i in range(n):
#     w[i] = randint(1, 10000)
# print(w)
count = 0

def check(P):
    m = 0
    ik = 1
    for i in range(n):
        global count
        count += 1
        new = m + w[i]
        if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
    return True

s = max(sum(w)//k, max(w))
e = sum(w)

while True:
    P = (s + e)//2
    # print("s:{}, e:{}, P:{}".format(s, e, P))
    if s == e:
        break
    if check(P):
        e = P
    else:
        s = P + 1
            
        
print(P)
# print(count) n, k = map(int, input().rstrip().split()) n map(int, input().rstrip().split()) map int input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split k 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 w = [0 for _ in range(n)] w [0 for _ in range(n)] for i in range(n):
    w[i] = int(input())
    
# from random import randint
# n = 100000
# k = 10000
# w = [0 for _ in range(n)]
# for i in range(n):
#     w[i] = randint(1, 10000)
# print(w) i range(n) range n w[i] = int(input()) w[i] w i int(input()) int input() input count = 0 count 0 def check(P):
    m = 0
    ik = 1
    for i in range(n):
        global count
        count += 1
        new = m + w[i]
        if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
    return True check m = 0 m 0 ik = 1 ik 1 for i in range(n):
        global count
        count += 1
        new = m + w[i]
        if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
     i range(n) range n global count count += 1 count 1 new = m + w[i] new m + w[i] m w[i] w i if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
     new > P new P m = w[i] m w[i] w i ik += 1 ik 1 if ik > k:
                return False
         ik > k ik k return False False m = new m new return True True P P s = max(sum(w)//k, max(w)) s max(sum(w)//k, max(w)) max sum(w)//k sum(w) sum w k max(w) max w e = sum(w) e sum(w) sum w while True:
    P = (s + e)//2
    # print("s:{}, e:{}, P:{}".format(s, e, P))
    if s == e:
        break
    if check(P):
        e = P
    else:
        s = P + 1
            
         True P = (s + e)//2 P (s + e)//2 s + e s e 2 if s == e:
        break
     s == e s e break if check(P):
        e = P
    else:
        s = P + 1
            
         check(P) check P e = P e P s = P + 1 s P + 1 P 1 print(P) print P n, k = map(int, input().rstrip().split()) map(int, input().rstrip().split()) n e = sum(w) sum(w) e P = (s + e)//2 (s + e)//2 P e = P P e def check(P):
    m = 0
    ik = 1
    for i in range(n):
        global count
        count += 1
        new = m + w[i]
        if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
    return True def check(P):
    m = 0
    ik = 1
    for i in range(n):
        global count
        count += 1
        new = m + w[i]
        if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
    return True check s = max(sum(w)//k, max(w)) max(sum(w)//k, max(w)) s s = P + 1 P + 1 s k = map(int, input().rstrip().split()) map(int, input().rstrip().split()) k w = [0 for _ in range(n)] [0 for _ in range(n)] w count = 0 0 count
# coding: utf-8

n, k = map(int, input().rstrip().split())
w = [0 for _ in range(n)]
for i in range(n):
    w[i] = int(input())
    
# from random import randint
# n = 100000
# k = 10000
# w = [0 for _ in range(n)]
# for i in range(n):
#     w[i] = randint(1, 10000)
# print(w)
count = 0

def check(P):
    m = 0
    ik = 1
    for i in range(n):
        global count
        count += 1
        new = m + w[i]
        if new > P:
            m = w[i]
            ik += 1
            if ik > k:
                return False
        else:
            m = new
    return True

s = max(sum(w)//k, max(w))
e = sum(w)

while True:
    P = (s + e)//2
    # print("s:{}, e:{}, P:{}".format(s, e, P))
    if s == e:
        break
    if check(P):
        e = P
    else:
        s = P + 1
            
        
print(P)
# print(count)