def allocate(n,w,k,p):
	t=0
	c=1
	for i in range(n):
		if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		t+=w[i]
	return 0

n,k=map(int,input().split())
w=[0]*n
m=(1<<30)*-1
s=0
for i in range(n):
	w[i]=int(input())
	m=max(m,w[i])
	s+=w[i]

i=m
j=s
while (i<=j):
	guess = int(i+(j-i)/2)
	if allocate(n,w,k,guess) < 0:
		i = guess + 1
	else:
		j = guess - 1
print(i)
 def allocate(n,w,k,p):
	t=0
	c=1
	for i in range(n):
		if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		t+=w[i]
	return 0 allocate t=0 t 0 c=1 c 1 for i in range(n):
		if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		t+=w[i]
	 i range(n) range n if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		 t + w[i] > p t + w[i] t w[i] w i p t=0 t 0 c+=1 c 1 if c > k:
				return -1
		 c > k c k return -1 -1 t+=w[i] t w[i] w i return 0 0 n n w w k k p p n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w=[0]*n w [0]*n [0] 0 n m=(1<<30)*-1 m (1<<30)*-1 1<<30 1 30 -1 s=0 s 0 for i in range(n):
	w[i]=int(input())
	m=max(m,w[i])
	s+=w[i] i range(n) range n w[i]=int(input()) w[i] w i int(input()) int input() input m=max(m,w[i]) m max(m,w[i]) max m w[i] w i s+=w[i] s w[i] w i i=m i m j=s j s while (i<=j):
	guess = int(i+(j-i)/2)
	if allocate(n,w,k,guess) < 0:
		i = guess + 1
	else:
		j = guess - 1 i<=j i j guess = int(i+(j-i)/2) guess int(i+(j-i)/2) int i+(j-i)/2 i (j-i)/2 j-i j i 2 if allocate(n,w,k,guess) < 0:
		i = guess + 1
	else:
		j = guess - 1 allocate(n,w,k,guess) < 0 allocate(n,w,k,guess) allocate n w k guess 0 i = guess + 1 i guess + 1 guess 1 j = guess - 1 j guess - 1 guess 1 print(i) print i i = guess + 1 guess + 1 i m=(1<<30)*-1 (1<<30)*-1 m k=map(int,input().split()) map(int,input().split()) k n,k=map(int,input().split()) map(int,input().split()) n guess = int(i+(j-i)/2) int(i+(j-i)/2) guess j=s s j j = guess - 1 guess - 1 j def allocate(n,w,k,p):
	t=0
	c=1
	for i in range(n):
		if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		t+=w[i]
	return 0 def allocate(n,w,k,p):
	t=0
	c=1
	for i in range(n):
		if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		t+=w[i]
	return 0 allocate m=max(m,w[i]) max(m,w[i]) m s=0 0 s s+=w[i] w[i] s i=m m i w=[0]*n [0]*n w
def allocate(n,w,k,p):
	t=0
	c=1
	for i in range(n):
		if t + w[i] > p:
			t=0
			c+=1
			if c > k:
				return -1
		t+=w[i]
	return 0

n,k=map(int,input().split())
w=[0]*n
m=(1<<30)*-1
s=0
for i in range(n):
	w[i]=int(input())
	m=max(m,w[i])
	s+=w[i]

i=m
j=s
while (i<=j):
	guess = int(i+(j-i)/2)
	if allocate(n,w,k,guess) < 0:
		i = guess + 1
	else:
		j = guess - 1
print(i)

