def n_nimotsu_if_P(P, k, arr):
	weight = 0
	n_trucks = 1
	for i, a in enumerate(arr):
		if P < a:
			return i
		if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		if n_trucks == k + 1:
			return i

	return len(arr)

n, k = map(int, input().split())
luggages = []
for _ in range(n):
	luggages.append(int(input()))

left, right = 0, 10000 * n
i_break = 0
while right - left > 1:
	mid = (left + right) // 2
	if n <= n_nimotsu_if_P(mid, k, luggages):
		right = mid
	else:
		left = mid

print(right) def n_nimotsu_if_P(P, k, arr):
	weight = 0
	n_trucks = 1
	for i, a in enumerate(arr):
		if P < a:
			return i
		if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		if n_trucks == k + 1:
			return i

	return len(arr) n_nimotsu_if_P weight = 0 weight 0 n_trucks = 1 n_trucks 1 for i, a in enumerate(arr):
		if P < a:
			return i
		if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		if n_trucks == k + 1:
			return i

	 i a enumerate(arr) enumerate arr if P < a:
			return i
		 P < a P a return i i if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		 weight + a <= P weight + a weight a P weight += a weight a n_trucks += 1 n_trucks 1 weight = a weight a if n_trucks == k + 1:
			return i

	 n_trucks == k + 1 n_trucks k + 1 k 1 return i i return len(arr) len(arr) len arr P P k k arr arr n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k luggages = [] luggages [] for _ in range(n):
	luggages.append(int(input())) _ range(n) range n luggages.append(int(input())) luggages.append luggages append int(input()) int input() input left, right = 0, 10000 * n left 0 right 10000 * n 10000 n i_break = 0 i_break 0 while right - left > 1:
	mid = (left + right) // 2
	if n <= n_nimotsu_if_P(mid, k, luggages):
		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 n <= n_nimotsu_if_P(mid, k, luggages):
		right = mid
	else:
		left = mid n <= n_nimotsu_if_P(mid, k, luggages) n n_nimotsu_if_P(mid, k, luggages) n_nimotsu_if_P mid k luggages right = mid right mid left = mid left mid print(right) print right left, right = 0, 10000 * n 0 left i_break = 0 0 i_break mid = (left + right) // 2 (left + right) // 2 mid right = mid mid right luggages = [] [] luggages def n_nimotsu_if_P(P, k, arr):
	weight = 0
	n_trucks = 1
	for i, a in enumerate(arr):
		if P < a:
			return i
		if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		if n_trucks == k + 1:
			return i

	return len(arr) def n_nimotsu_if_P(P, k, arr):
	weight = 0
	n_trucks = 1
	for i, a in enumerate(arr):
		if P < a:
			return i
		if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		if n_trucks == k + 1:
			return i

	return len(arr) n_nimotsu_if_P right = 0, 10000 * n 10000 * n right k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n left = mid mid left
def n_nimotsu_if_P(P, k, arr):
	weight = 0
	n_trucks = 1
	for i, a in enumerate(arr):
		if P < a:
			return i
		if weight + a <= P:
			weight += a
		else:
			n_trucks += 1
			weight = a
		if n_trucks == k + 1:
			return i

	return len(arr)

n, k = map(int, input().split())
luggages = []
for _ in range(n):
	luggages.append(int(input()))

left, right = 0, 10000 * n
i_break = 0
while right - left > 1:
	mid = (left + right) // 2
	if n <= n_nimotsu_if_P(mid, k, luggages):
		right = mid
	else:
		left = mid

print(right)
