import sys
'''
	??\?????????????????????
'''
_allinput = []
for inp in sys.stdin:
	_allinput += inp.strip().split(" ")
def _input():
	for put in _allinput:
		yield put
_obj = _input();
def __input():
	return _obj.__next__()
def nextInt():
	return int(__input())

def check(lst,L):
	tot = 1
	curSum = 0
	for i in lst:
		if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	return tot

def solve(lst,m):
	l,r = max(lst), 100000 * 10000
	while l != r:
		mid = int((l+r)/2)
		if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	return l


n,m = nextInt(),nextInt()
if m > 0 or n > 0:
	lst = [nextInt() for i in range(0,n)]
	print(solve(lst,m)) import sys sys '''
	??\?????????????????????
''' _allinput = [] _allinput [] for inp in sys.stdin:
	_allinput += inp.strip().split(" ") inp sys.stdin sys stdin _allinput += inp.strip().split(" ") _allinput inp.strip().split(" ") inp.strip().split inp.strip() inp.strip inp strip split " " def _input():
	for put in _allinput:
		yield put _input for put in _allinput:
		yield put put _allinput yield put put _obj = _input() _obj _input() _input def __input():
	return _obj.__next__() __input return _obj.__next__() _obj.__next__() _obj.__next__ _obj __next__ def nextInt():
	return int(__input()) nextInt return int(__input()) int(__input()) int __input() __input def check(lst,L):
	tot = 1
	curSum = 0
	for i in lst:
		if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	return tot check tot = 1 tot 1 curSum = 0 curSum 0 for i in lst:
		if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	 i lst if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	 curSum + i <= L curSum + i curSum i L curSum += i curSum i curSum = i curSum i tot += 1 tot 1 return tot tot lst lst L L def solve(lst,m):
	l,r = max(lst), 100000 * 10000
	while l != r:
		mid = int((l+r)/2)
		if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	return l solve l,r = max(lst), 100000 * 10000 l max(lst) max lst r 100000 * 10000 100000 10000 while l != r:
		mid = int((l+r)/2)
		if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	 l != r l r mid = int((l+r)/2) mid int((l+r)/2) int (l+r)/2 l+r l r 2 if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	 check(lst,mid) <= m check(lst,mid) check lst mid m r = mid r mid l = mid + 1 l mid + 1 mid 1 return l l lst lst m m n,m = nextInt(),nextInt() n nextInt() nextInt m nextInt() nextInt if m > 0 or n > 0:
	lst = [nextInt() for i in range(0,n)]
	print(solve(lst,m)) m > 0 or n > 0 m > 0 m 0 n > 0 n 0 nextInt() for i in range(0,n) for i in range(0,n) i range(0,n) range 0 n for i in range(0,n) nextInt() nextInt lst = [nextInt() for i in range(0,n)] lst [nextInt() for i in range(0,n)] print(solve(lst,m)) print solve(lst,m) solve lst m _allinput = [] [] _allinput n,m = nextInt(),nextInt() nextInt() n _allinput += inp.strip().split(" ") inp.strip().split(" ") _allinput _obj = _input() _input() _obj def solve(lst,m):
	l,r = max(lst), 100000 * 10000
	while l != r:
		mid = int((l+r)/2)
		if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	return l def solve(lst,m):
	l,r = max(lst), 100000 * 10000
	while l != r:
		mid = int((l+r)/2)
		if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	return l solve def _input():
	for put in _allinput:
		yield put def _input():
	for put in _allinput:
		yield put _input def nextInt():
	return int(__input()) def nextInt():
	return int(__input()) nextInt lst = [nextInt() for i in range(0,n)] [nextInt() for i in range(0,n)] lst def check(lst,L):
	tot = 1
	curSum = 0
	for i in lst:
		if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	return tot def check(lst,L):
	tot = 1
	curSum = 0
	for i in lst:
		if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	return tot check m = nextInt(),nextInt() nextInt() m
import sys
'''
	??\?????????????????????
'''
_allinput = []
for inp in sys.stdin:
	_allinput += inp.strip().split(" ")
def _input():
	for put in _allinput:
		yield put
_obj = _input();
def __input():
	return _obj.__next__()
def nextInt():
	return int(__input())

def check(lst,L):
	tot = 1
	curSum = 0
	for i in lst:
		if curSum + i <= L:
			curSum += i
		else:
			curSum = i
			tot += 1
	return tot

def solve(lst,m):
	l,r = max(lst), 100000 * 10000
	while l != r:
		mid = int((l+r)/2)
		if check(lst,mid) <= m:
			r = mid
		else:
			l = mid + 1
	return l


n,m = nextInt(),nextInt()
if m > 0 or n > 0:
	lst = [nextInt() for i in range(0,n)]
	print(solve(lst,m))