#include <stdio.h>
#include <stdbool.h>

//????????????????????£?¨?.
bool ok(int n, int m, int k);

//??°?????????????????°.
int w[100000] = {};			//???????????????.

int main(void) {
	int n = 0;				//???????????°.
	int k = 0;				//?????????????????°??°.

	int l = 0;				//??????.
	int h = 0;				//??????.
	int m = 0;				//?????????.

	int i = 0;

	scanf("%d %d", &n, &k);

	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
		h += w[i];
	}

	while (l < h) {
		m = (l + h) / 2;

		if (ok(n, m, k))
			h = m;
		else
			l = m + 1;
	}

	printf("%d\n", h);

	return 0;
}

bool ok(int n, int m, int k) {
	int i = 0;
	int sum = 0;			//???????????????????????§????????????.
	int num = 1;			//?????£????????????????????°??°.

	for (i = 0; i < n; i++) {
		if (w[i] > m)
			return false;

		sum += w[i];

		if (sum > m)
			sum = w[i], num++;
	}

	if (num <= k)
		return true;
	else
		return false;
}