def allocation():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
    min = 0
    max = 100000000000
    while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
    print(max)

def check(n, k, w, p):
    t = 0
    now = 0
    for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
    if now > 0:
        t += 1
    if t > k:
        return False
    else:
        return True

if __name__ == '__main__':
    allocation() def allocation():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
    min = 0
    max = 100000000000
    while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
    print(max) allocation n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w = [] w [] for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
     i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input min = 0 min 0 max = 100000000000 max 100000000000 while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
     min + 1 != max min + 1 min 1 max mid =(min + max) // 2 mid (min + max) // 2 min + max min max 2 if check(n, k, w, mid):
            max = mid
        else:
            min = mid
     check(n, k, w, mid) check n k w mid max = mid max mid min = mid min mid print(max) print max def check(n, k, w, p):
    t = 0
    now = 0
    for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
    if now > 0:
        t += 1
    if t > k:
        return False
    else:
        return True check t = 0 t 0 now = 0 now 0 for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
     i range(n) range n if (w[i] > p):
            return False
         w[i] > p w[i] w i p return False False if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
     now + w[i] > p now + w[i] now w[i] w i p t += 1 t 1 now = w[i] now w[i] w i now += w[i] now w[i] w i if now > 0:
        t += 1
     now > 0 now 0 t += 1 t 1 if t > k:
        return False
    else:
        return True t > k t k return False False return True True n n k k w w p p if __name__ == '__main__':
    allocation() __name__ == '__main__' __name__ '__main__' allocation() allocation def allocation():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
    min = 0
    max = 100000000000
    while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
    print(max) def allocation():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
    min = 0
    max = 100000000000
    while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
    print(max) allocation def check(n, k, w, p):
    t = 0
    now = 0
    for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
    if now > 0:
        t += 1
    if t > k:
        return False
    else:
        return True def check(n, k, w, p):
    t = 0
    now = 0
    for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
    if now > 0:
        t += 1
    if t > k:
        return False
    else:
        return True check
def allocation():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))

    # 最大積載量pを算出
    min = 0
    max = 100000000000
    while min + 1 != max:
        mid =(min + max) // 2
        if check(n, k, w, mid):
            max = mid
        else:
            min = mid
    print(max)

def check(n, k, w, p):
    t = 0
    now = 0
    for i in range(n):
        if (w[i] > p):
            return False
        if (now + w[i] > p):
            t += 1
            now = w[i]
        else:
            now += w[i]
    if now > 0:
        t += 1
    if t > k:
        return False
    else:
        return True

if __name__ == '__main__':
    allocation()
