import sys

def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
sum = 0
maxi = 0
for i in range(n):
	weight = int(input())
	weights[i] = weight
	sum += weight
	maxi = max(maxi, weight)

if k == 1:
	print(sum)
	sys.exit()

start = maxi
end = sum
mid = 0
while start <= end:
	mid = int(start + (end - start) / 2)
	can_alloc = check_alloc(weights, k, mid)
	if can_alloc == False:
		start = mid + 1
	else:
		if start == end: break
		end = mid

print(mid)
 import sys sys def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True check_alloc num = 1 num 1 cur = 0 cur 0 for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	 i range(len(weights)) range len(weights) len weights w = weights[i] w weights[i] weights i if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	 cur + w > cpct cur + w cur w cpct cur = w cur w num += 1 num 1 if num > cnt or cur > cpct:
				return False
		 num > cnt or cur > cpct num > cnt num cnt cur > cpct cur cpct return False False cur += w cur w return True True weights weights cnt cnt cpct cpct n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k weights = [0] * n weights [0] * n [0] 0 n sum = 0 sum 0 maxi = 0 maxi 0 for i in range(n):
	weight = int(input())
	weights[i] = weight
	sum += weight
	maxi = max(maxi, weight) i range(n) range n weight = int(input()) weight int(input()) int input() input weights[i] = weight weights[i] weights i weight sum += weight sum weight maxi = max(maxi, weight) maxi max(maxi, weight) max maxi weight if k == 1:
	print(sum)
	sys.exit() k == 1 k 1 print(sum) print sum sys.exit() sys.exit sys exit start = maxi start maxi end = sum end sum mid = 0 mid 0 while start <= end:
	mid = int(start + (end - start) / 2)
	can_alloc = check_alloc(weights, k, mid)
	if can_alloc == False:
		start = mid + 1
	else:
		if start == end: break
		end = mid start <= end start end mid = int(start + (end - start) / 2) mid int(start + (end - start) / 2) int start + (end - start) / 2 start (end - start) / 2 end - start end start 2 can_alloc = check_alloc(weights, k, mid) can_alloc check_alloc(weights, k, mid) check_alloc weights k mid if can_alloc == False:
		start = mid + 1
	else:
		if start == end: break
		end = mid can_alloc == False can_alloc False start = mid + 1 start mid + 1 mid 1 if start == end: break
		 start == end start end end = mid end mid print(mid) print mid sum = 0 0 sum sum += weight weight sum weights = [0] * n [0] * n weights k = map(int, input().split()) map(int, input().split()) k mid = int(start + (end - start) / 2) int(start + (end - start) / 2) mid n, k = map(int, input().split()) map(int, input().split()) n can_alloc = check_alloc(weights, k, mid) check_alloc(weights, k, mid) can_alloc start = mid + 1 mid + 1 start end = mid mid end maxi = 0 0 maxi weight = int(input()) int(input()) weight start = maxi maxi start mid = 0 0 mid def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True check_alloc end = sum sum end maxi = max(maxi, weight) max(maxi, weight) maxi
import sys

def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
sum = 0
maxi = 0
for i in range(n):
	weight = int(input())
	weights[i] = weight
	sum += weight
	maxi = max(maxi, weight)

if k == 1:
	print(sum)
	sys.exit()

start = maxi
end = sum
mid = 0
while start <= end:
	mid = int(start + (end - start) / 2)
	can_alloc = check_alloc(weights, k, mid)
	if can_alloc == False:
		start = mid + 1
	else:
		if start == end: break
		end = mid

print(mid)

