import math

tr = []

def check(n, k, P):
    i = 0
    for j in range(k):
        s = 0
        while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
    return i

def solve(n, k):
    left = 0
    right = 100000 * 100000
    while right - left > 1:
        mid = math.floor((left+right) / 2)
        v = check(n, k, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

def main():
    input_line = input().split(" ")
    n = int(input_line[0])
    k = int(input_line[1])
    
    for _ in range(n):
        w = int(input())
        tr.append(w)

    ans = solve(n, k)
    
    print(ans)

if __name__ == '__main__':
    main() import math math tr = [] tr [] def check(n, k, P):
    i = 0
    for j in range(k):
        s = 0
        while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
    return i check i = 0 i 0 for j in range(k):
        s = 0
        while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
     j range(k) range k s = 0 s 0 while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
     s + tr[i] <= P s + tr[i] s tr[i] tr i P s += tr[i] s tr[i] tr i i += 1 i 1 if i == n:
                return n
     i == n i n return n n return i i n n k k P P def solve(n, k):
    left = 0
    right = 100000 * 100000
    while right - left > 1:
        mid = math.floor((left+right) / 2)
        v = check(n, k, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right solve left = 0 left 0 right = 100000 * 100000 right 100000 * 100000 100000 100000 while right - left > 1:
        mid = math.floor((left+right) / 2)
        v = check(n, k, mid)
        if v >= n:
            right = mid
        else:
            left = mid
     right - left > 1 right - left right left 1 mid = math.floor((left+right) / 2) mid math.floor((left+right) / 2) math.floor math floor (left+right) / 2 left+right left right 2 v = check(n, k, mid) v check(n, k, mid) check n k mid if v >= n:
            right = mid
        else:
            left = mid
     v >= n v n right = mid right mid left = mid left mid return right right n n k k def main():
    input_line = input().split(" ")
    n = int(input_line[0])
    k = int(input_line[1])
    
    for _ in range(n):
        w = int(input())
        tr.append(w)

    ans = solve(n, k)
    
    print(ans) main input_line = input().split(" ") input_line input().split(" ") ().split () input split " " n = int(input_line[0]) n int(input_line[0]) int input_line[0] input_line 0 k = int(input_line[1]) k int(input_line[1]) int input_line[1] input_line 1 for _ in range(n):
        w = int(input())
        tr.append(w)

     _ range(n) range n w = int(input()) w int(input()) int input() input tr.append(w) tr.append tr append w ans = solve(n, k) ans solve(n, k) solve n k print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    input_line = input().split(" ")
    n = int(input_line[0])
    k = int(input_line[1])
    
    for _ in range(n):
        w = int(input())
        tr.append(w)

    ans = solve(n, k)
    
    print(ans) def main():
    input_line = input().split(" ")
    n = int(input_line[0])
    k = int(input_line[1])
    
    for _ in range(n):
        w = int(input())
        tr.append(w)

    ans = solve(n, k)
    
    print(ans) main def check(n, k, P):
    i = 0
    for j in range(k):
        s = 0
        while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
    return i def check(n, k, P):
    i = 0
    for j in range(k):
        s = 0
        while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
    return i check def solve(n, k):
    left = 0
    right = 100000 * 100000
    while right - left > 1:
        mid = math.floor((left+right) / 2)
        v = check(n, k, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right def solve(n, k):
    left = 0
    right = 100000 * 100000
    while right - left > 1:
        mid = math.floor((left+right) / 2)
        v = check(n, k, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right solve tr = [] [] tr
import math

tr = []

def check(n, k, P):
    i = 0
    for j in range(k):
        s = 0
        while s + tr[i] <= P:
            s += tr[i]
            i += 1
            if i == n:
                return n
    return i

def solve(n, k):
    left = 0
    right = 100000 * 100000
    while right - left > 1:
        mid = math.floor((left+right) / 2)
        v = check(n, k, mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

def main():
    input_line = input().split(" ")
    n = int(input_line[0])
    k = int(input_line[1])
    
    for _ in range(n):
        w = int(input())
        tr.append(w)

    ans = solve(n, k)
    
    print(ans)

if __name__ == '__main__':
    main()
