import sys

global n, k, T


def cal_v(P):
    j = 0
    for i in range(k):
        con = 0
        while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
    return j


def cal_ans():
    left = 0
    right = sum(T)
    mid = (right-left) // 2
    while right - left > 1:
        mid = left + (right-left)//2
        if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
    return right

if __name__ == "__main__":
    n, k = map(int, sys.stdin.readline().split())
    T = list(map(int, sys.stdin.readlines()))
    ans = cal_ans()
    print(ans) import sys sys global n, k, T def cal_v(P):
    j = 0
    for i in range(k):
        con = 0
        while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
    return j cal_v j = 0 j 0 for i in range(k):
        con = 0
        while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
     i range(k) range k con = 0 con 0 while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
     con + T[j] <= P con + T[j] con T[j] T j P con += T[j] con T[j] T j j += 1 j 1 if j == n:
                return n
     j == n j n return n n return j j P P def cal_ans():
    left = 0
    right = sum(T)
    mid = (right-left) // 2
    while right - left > 1:
        mid = left + (right-left)//2
        if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
    return right cal_ans left = 0 left 0 right = sum(T) right sum(T) sum T mid = (right-left) // 2 mid (right-left) // 2 right-left right left 2 while right - left > 1:
        mid = left + (right-left)//2
        if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
     right - left > 1 right - left right left 1 mid = left + (right-left)//2 mid left + (right-left)//2 left (right-left)//2 right-left right left 2 if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
     cal_v(mid) >= n cal_v(mid) cal_v mid n right = mid right mid left = mid left mid return right right if __name__ == "__main__":
    n, k = map(int, sys.stdin.readline().split())
    T = list(map(int, sys.stdin.readlines()))
    ans = cal_ans()
    print(ans) __name__ == "__main__" __name__ "__main__" n, k = map(int, sys.stdin.readline().split()) n map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split k T = list(map(int, sys.stdin.readlines())) T list(map(int, sys.stdin.readlines())) list map(int, sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines ans = cal_ans() ans cal_ans() cal_ans print(ans) print ans global n, k, T def cal_ans():
    left = 0
    right = sum(T)
    mid = (right-left) // 2
    while right - left > 1:
        mid = left + (right-left)//2
        if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
    return right def cal_ans():
    left = 0
    right = sum(T)
    mid = (right-left) // 2
    while right - left > 1:
        mid = left + (right-left)//2
        if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
    return right cal_ans k = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) k def cal_v(P):
    j = 0
    for i in range(k):
        con = 0
        while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
    return j def cal_v(P):
    j = 0
    for i in range(k):
        con = 0
        while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
    return j cal_v ans = cal_ans() cal_ans() ans T = list(map(int, sys.stdin.readlines())) list(map(int, sys.stdin.readlines())) T n, k = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) n
import sys

global n, k, T


def cal_v(P):
    j = 0
    for i in range(k):
        con = 0
        while con + T[j] <= P:
            con += T[j]
            j += 1
            if j == n:
                return n
    return j


def cal_ans():
    left = 0
    right = sum(T)
    mid = (right-left) // 2
    while right - left > 1:
        mid = left + (right-left)//2
        if cal_v(mid) >= n:
            right = mid
        else:
            left = mid
    return right

if __name__ == "__main__":
    n, k = map(int, sys.stdin.readline().split())
    T = list(map(int, sys.stdin.readlines()))
    ans = cal_ans()
    print(ans)