import sys

def value(w,n,P):

	tmp_w = 0
	k = 1

	for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	return k


def test():

	inputs = list(map(int,sys.stdin.readline().split()))
	n = inputs[0]
	k = inputs[1]
	w = []

	max = 0
	sum = 0

	for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	print(max)

if __name__ == "__main__":
	test()
 import sys sys def value(w,n,P):

	tmp_w = 0
	k = 1

	for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	return k value tmp_w = 0 tmp_w 0 k = 1 k 1 for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	 i range(n) range n if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	 tmp_w + w[i] <= P tmp_w + w[i] tmp_w w[i] w i P tmp_w += w[i] tmp_w w[i] w i tmp_w = w[i] tmp_w w[i] w i k += 1 k 1 return k k w w n n P P def test():

	inputs = list(map(int,sys.stdin.readline().split()))
	n = inputs[0]
	k = inputs[1]
	w = []

	max = 0
	sum = 0

	for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	print(max) test inputs = list(map(int,sys.stdin.readline().split())) inputs list(map(int,sys.stdin.readline().split())) list 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 n = inputs[0] n inputs[0] inputs 0 k = inputs[1] k inputs[1] inputs 1 w = [] w [] max = 0 max 0 sum = 0 sum 0 for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	 i range(n) range n w.append(int(sys.stdin.readline())) w.append w append int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline if w[i] > max:
			max = w[i]

		 w[i] > max w[i] w i max max = w[i] max w[i] w i sum += w[i] sum w[i] w i while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	 max != sum max sum mid = (max + sum) // 2 mid (max + sum) // 2 max + sum max sum 2 if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	 value(w,n,mid) > k value(w,n,mid) value w n mid k max = mid + 1 max mid + 1 mid 1 sum = mid sum mid print(max) print max if __name__ == "__main__":
	test() __name__ == "__main__" __name__ "__main__" test() test def value(w,n,P):

	tmp_w = 0
	k = 1

	for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	return k def value(w,n,P):

	tmp_w = 0
	k = 1

	for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	return k value def test():

	inputs = list(map(int,sys.stdin.readline().split()))
	n = inputs[0]
	k = inputs[1]
	w = []

	max = 0
	sum = 0

	for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	print(max) def test():

	inputs = list(map(int,sys.stdin.readline().split()))
	n = inputs[0]
	k = inputs[1]
	w = []

	max = 0
	sum = 0

	for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	print(max) test
import sys

def value(w,n,P):

	tmp_w = 0
	k = 1

	for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	return k


def test():

	inputs = list(map(int,sys.stdin.readline().split()))
	n = inputs[0]
	k = inputs[1]
	w = []

	max = 0
	sum = 0

	for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	print(max)

if __name__ == "__main__":
	test()

