# Aizu Problem ALDS_1_4_D: Allocation
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def check(n, k, W, p):
    idx = 0
    for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
    return False

    
n, k = [int(_) for _ in input().split()]
W = [int(input()) for _ in range(n)]
left, right = 0, 10**16
while right - left > 1:
    mid = (left + right) // 2
    if check(n, k, W, mid):
        right = mid
    else:
        left = mid
print(right) import sys, math, os sys math os PYDEV = os.environ.get('PYDEV') PYDEV os.environ.get('PYDEV') os.environ.get os.environ os environ get 'PYDEV' if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt") PYDEV=="True" PYDEV "True" sys.stdin = open("sample-input2.txt", "rt") sys.stdin sys stdin open("sample-input2.txt", "rt") open "sample-input2.txt" "rt" def check(n, k, W, p):
    idx = 0
    for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
    return False

     check idx = 0 idx 0 for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
     i range(k) range k S = 0 S 0 while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
     W[idx] + S <= p W[idx] + S W[idx] W idx S p S += W[idx] S W[idx] W idx idx += 1 idx 1 if idx == n:
                return True
     idx == n idx n return True True return False False n n k k W W p p int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ n, k = [int(_) for _ in input().split()] n [int(_) for _ in input().split()] k int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input W = [int(input()) for _ in range(n)] W [int(input()) for _ in range(n)] left, right = 0, 10**16 left 0 right 10**16 10 16 while right - left > 1:
    mid = (left + right) // 2
    if check(n, k, W, mid):
        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 if check(n, k, W, mid):
        right = mid
    else:
        left = mid check(n, k, W, mid) check n k W mid right = mid right mid left = mid left mid print(right) print right k = [int(_) for _ in input().split()] [int(_) for _ in input().split()] k W = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W right = mid mid right right = 0, 10**16 10**16 right mid = (left + right) // 2 (left + right) // 2 mid def check(n, k, W, p):
    idx = 0
    for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
    return False

     def check(n, k, W, p):
    idx = 0
    for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
    return False

     check PYDEV = os.environ.get('PYDEV') os.environ.get('PYDEV') PYDEV left = mid mid left n, k = [int(_) for _ in input().split()] [int(_) for _ in input().split()] n left, right = 0, 10**16 0 left
# Aizu Problem ALDS_1_4_D: Allocation
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def check(n, k, W, p):
    idx = 0
    for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
    return False

    
n, k = [int(_) for _ in input().split()]
W = [int(input()) for _ in range(n)]
left, right = 0, 10**16
while right - left > 1:
    mid = (left + right) // 2
    if check(n, k, W, mid):
        right = mid
    else:
        left = mid
print(right)