def main():
	n, n_truck = map(int, input().split())
	w_list = []

	for _ in range(n):
		w_list.append(int(input()))

	print(b_search(w_list, n_truck))
 
def b_search(w_list, n_truck):
	left = max(w_list)
	right = sum(w_list)
	while left < right:
		mid = int((left+right) / 2)
		if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	return mid


def check(w_list, n_truck, p):
	truck_count = 1
	tmp_truck = 0

	for w in w_list:
		tmp_truck += w
		if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		if truck_count > n_truck:
			return False

	return True






if __name__ == '__main__':
    main() def main():
	n, n_truck = map(int, input().split())
	w_list = []

	for _ in range(n):
		w_list.append(int(input()))

	print(b_search(w_list, n_truck))
  main n, n_truck = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split n_truck w_list = [] w_list [] for _ in range(n):
		w_list.append(int(input()))

	 _ range(n) range n w_list.append(int(input())) w_list.append w_list append int(input()) int input() input print(b_search(w_list, n_truck)) print b_search(w_list, n_truck) b_search w_list n_truck def b_search(w_list, n_truck):
	left = max(w_list)
	right = sum(w_list)
	while left < right:
		mid = int((left+right) / 2)
		if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	return mid b_search left = max(w_list) left max(w_list) max w_list right = sum(w_list) right sum(w_list) sum w_list while left < right:
		mid = int((left+right) / 2)
		if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	 left < right left right mid = int((left+right) / 2) mid int((left+right) / 2) int (left+right) / 2 left+right left right 2 if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	 check(w_list, n_truck, mid) check w_list n_truck mid right = mid right mid mid += 1 mid 1 left = mid left mid return mid mid w_list w_list n_truck n_truck def check(w_list, n_truck, p):
	truck_count = 1
	tmp_truck = 0

	for w in w_list:
		tmp_truck += w
		if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		if truck_count > n_truck:
			return False

	return True check truck_count = 1 truck_count 1 tmp_truck = 0 tmp_truck 0 for w in w_list:
		tmp_truck += w
		if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		if truck_count > n_truck:
			return False

	 w w_list tmp_truck += w tmp_truck w if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		 tmp_truck > p tmp_truck p truck_count += 1 truck_count 1 tmp_truck = w tmp_truck w if truck_count > n_truck:
			return False

	 truck_count > n_truck truck_count n_truck return False False return True True w_list w_list n_truck n_truck p p if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def check(w_list, n_truck, p):
	truck_count = 1
	tmp_truck = 0

	for w in w_list:
		tmp_truck += w
		if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		if truck_count > n_truck:
			return False

	return True def check(w_list, n_truck, p):
	truck_count = 1
	tmp_truck = 0

	for w in w_list:
		tmp_truck += w
		if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		if truck_count > n_truck:
			return False

	return True check def main():
	n, n_truck = map(int, input().split())
	w_list = []

	for _ in range(n):
		w_list.append(int(input()))

	print(b_search(w_list, n_truck))
  def main():
	n, n_truck = map(int, input().split())
	w_list = []

	for _ in range(n):
		w_list.append(int(input()))

	print(b_search(w_list, n_truck))
  main def b_search(w_list, n_truck):
	left = max(w_list)
	right = sum(w_list)
	while left < right:
		mid = int((left+right) / 2)
		if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	return mid def b_search(w_list, n_truck):
	left = max(w_list)
	right = sum(w_list)
	while left < right:
		mid = int((left+right) / 2)
		if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	return mid b_search
def main():
	n, n_truck = map(int, input().split())
	w_list = []

	for _ in range(n):
		w_list.append(int(input()))

	print(b_search(w_list, n_truck))
 
def b_search(w_list, n_truck):
	left = max(w_list)
	right = sum(w_list)
	while left < right:
		mid = int((left+right) / 2)
		if check(w_list, n_truck, mid):
			right = mid
		else:
			mid += 1
			left = mid

	return mid


def check(w_list, n_truck, p):
	truck_count = 1
	tmp_truck = 0

	for w in w_list:
		tmp_truck += w
		if tmp_truck > p:
			truck_count += 1
			tmp_truck = w
		if truck_count > n_truck:
			return False

	return True






if __name__ == '__main__':
    main()