
import sys
from sys import stdin
input = stdin.readline

n,k = (int(x) for x in input().split())
w = [int(input()) for i in range(n)]

# 最大積載Pのトラックで何個の荷物を積めるか
def check(P):
    i = 0
    for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i

def solve():
    left = 0
    right = 100000 * 10000  #荷物の個数 * 1個当たりの最大重量

    while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

print(solve()) import sys sys from sys import stdin input = stdin.readline input stdin.readline stdin readline int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n,k = (int(x) for x in input().split()) n (int(x) for x in input().split()) k int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input w = [int(input()) for i in range(n)] w [int(input()) for i in range(n)] def check(P):
    i = 0
    for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i check i = 0 i 0 for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
     j range(k) range k s = 0 s 0 while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
     s + w[i] <= P s + w[i] s w[i] w i P s += w[i] s w[i] w i i += 1 i 1 if i == n:
                return n
     i == n i n return n n return i i P P def solve():
    left = 0
    right = 100000 * 10000  #荷物の個数 * 1個当たりの最大重量

    while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right solve left = 0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
     right - left > 1 right - left right left 1 mid = (right + left)//2 mid (right + left)//2 right + left right left 2 v = check(mid) v check(mid) check mid if v >= n:
            right = mid
        else:
            left = mid
     v >= n v n right = mid right mid left = mid left mid return right right print(solve()) print solve() solve n,k = (int(x) for x in input().split()) (int(x) for x in input().split()) n def solve():
    left = 0
    right = 100000 * 10000  #荷物の個数 * 1個当たりの最大重量

    while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right def solve():
    left = 0
    right = 100000 * 10000  #荷物の個数 * 1個当たりの最大重量

    while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right solve input = stdin.readline stdin.readline input w = [int(input()) for i in range(n)] [int(input()) for i in range(n)] w def check(P):
    i = 0
    for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i def check(P):
    i = 0
    for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i check k = (int(x) for x in input().split()) (int(x) for x in input().split()) k

import sys
from sys import stdin
input = stdin.readline

n,k = (int(x) for x in input().split())
w = [int(input()) for i in range(n)]

# 最大積載Pのトラックで何個の荷物を積めるか
def check(P):
    i = 0
    for j in range(k):
        s = 0
        while  s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i

def solve():
    left = 0
    right = 100000 * 10000  #荷物の個数 * 1個当たりの最大重量

    while right - left > 1 :
        mid = (right + left)//2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right

print(solve())
