def isPacked(numcar, maxweight, packs):
	weight = 0  # 一台当たりの積載量
	k = 1  # トラック台数

	for j in range(len(packs)):
		if packs[j] > maxweight:
			return False
		if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		if k > numcar:
			return False

	return True


n, k = map(int, input().split())  # 5,3
W = []  # 8, 1, 7, 3, 9
PMAX = 0

for i in range(n):
	W.append(int(input()))
for i in W:
	PMAX = PMAX + i

#print(W)
#print(PMAX)

#print(isPacked(k, 5, W))
left = 0
right = PMAX + 1

while left < right:
	mid = (left + right) // 2
#	print('{0} {1} {2}'.format(left, mid, right))
	booleanPacked = isPacked(k, mid, W)
	if booleanPacked == True and isPacked(k, mid - 1, W) == False:
		print(mid)
		exit(0)
	elif booleanPacked == True:
		right = mid
	elif booleanPacked == False:
		left = mid + 1
 def isPacked(numcar, maxweight, packs):
	weight = 0  # 一台当たりの積載量
	k = 1  # トラック台数

	for j in range(len(packs)):
		if packs[j] > maxweight:
			return False
		if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		if k > numcar:
			return False

	return True isPacked weight = 0 weight 0 k = 1 k 1 for j in range(len(packs)):
		if packs[j] > maxweight:
			return False
		if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		if k > numcar:
			return False

	 j range(len(packs)) range len(packs) len packs if packs[j] > maxweight:
			return False
		 packs[j] > maxweight packs[j] packs j maxweight return False False if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		 weight + packs[j] > maxweight weight + packs[j] weight packs[j] packs j maxweight k = k + 1 k k + 1 k 1 weight = packs[j] weight packs[j] packs j weight = weight + packs[j] weight weight + packs[j] weight packs[j] packs j if k > numcar:
			return False

	 k > numcar k numcar return False False return True True numcar numcar maxweight maxweight packs packs n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k W = [] W [] PMAX = 0 PMAX 0 for i in range(n):
	W.append(int(input())) i range(n) range n W.append(int(input())) W.append W append int(input()) int input() input for i in W:
	PMAX = PMAX + i

#print(W)
#print(PMAX)

#print(isPacked(k, 5, W)) i W PMAX = PMAX + i PMAX PMAX + i PMAX i left = 0 left 0 right = PMAX + 1 right PMAX + 1 PMAX 1 while left < right:
	mid = (left + right) // 2
#	print('{0} {1} {2}'.format(left, mid, right))
	booleanPacked = isPacked(k, mid, W)
	if booleanPacked == True and isPacked(k, mid - 1, W) == False:
		print(mid)
		exit(0)
	elif booleanPacked == True:
		right = mid
	elif booleanPacked == False:
		left = mid + 1 left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 booleanPacked = isPacked(k, mid, W) booleanPacked isPacked(k, mid, W) isPacked k mid W if booleanPacked == True and isPacked(k, mid - 1, W) == False:
		print(mid)
		exit(0)
	elif booleanPacked == True:
		right = mid
	elif booleanPacked == False:
		left = mid + 1 booleanPacked == True and isPacked(k, mid - 1, W) == False booleanPacked == True booleanPacked True isPacked(k, mid - 1, W) == False isPacked(k, mid - 1, W) isPacked k mid - 1 mid 1 W False print(mid) print mid exit(0) exit 0 elif booleanPacked == True:
		right = mid
	 booleanPacked == True booleanPacked True right = mid right mid elif booleanPacked == False:
		left = mid + 1 booleanPacked == False booleanPacked False left = mid + 1 left mid + 1 mid 1 n, k = map(int, input().split()) map(int, input().split()) n booleanPacked = isPacked(k, mid, W) isPacked(k, mid, W) booleanPacked k = map(int, input().split()) map(int, input().split()) k right = PMAX + 1 PMAX + 1 right mid = (left + right) // 2 (left + right) // 2 mid PMAX = 0 0 PMAX W = [] [] W left = mid + 1 mid + 1 left def isPacked(numcar, maxweight, packs):
	weight = 0  # 一台当たりの積載量
	k = 1  # トラック台数

	for j in range(len(packs)):
		if packs[j] > maxweight:
			return False
		if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		if k > numcar:
			return False

	return True def isPacked(numcar, maxweight, packs):
	weight = 0  # 一台当たりの積載量
	k = 1  # トラック台数

	for j in range(len(packs)):
		if packs[j] > maxweight:
			return False
		if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		if k > numcar:
			return False

	return True isPacked left = 0 0 left right = mid mid right PMAX = PMAX + i PMAX + i PMAX
def isPacked(numcar, maxweight, packs):
	weight = 0  # 一台当たりの積載量
	k = 1  # トラック台数

	for j in range(len(packs)):
		if packs[j] > maxweight:
			return False
		if weight + packs[j] > maxweight:
			k = k + 1
			weight = packs[j]
		else:
			weight = weight + packs[j]
		if k > numcar:
			return False

	return True


n, k = map(int, input().split())  # 5,3
W = []  # 8, 1, 7, 3, 9
PMAX = 0

for i in range(n):
	W.append(int(input()))
for i in W:
	PMAX = PMAX + i

#print(W)
#print(PMAX)

#print(isPacked(k, 5, W))
left = 0
right = PMAX + 1

while left < right:
	mid = (left + right) // 2
#	print('{0} {1} {2}'.format(left, mid, right))
	booleanPacked = isPacked(k, mid, W)
	if booleanPacked == True and isPacked(k, mid - 1, W) == False:
		print(mid)
		exit(0)
	elif booleanPacked == True:
		right = mid
	elif booleanPacked == False:
		left = mid + 1

