#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005];
bool pd(int mid)
{
int cnt = 1;
int sum = a[1];
for (int i = 2; i <= n; i++)
{
if (sum + a[i] > mid)
{
cnt++;
sum = a[i];
}
else
sum += a[i];
}
return cnt <= m;
}
int main()
{
cin >> n >> m;
int l = 0, r = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", a + i);
l = max(l, a[i]);
r += a[i];
}
int ans = 0;
while (l <= r)
{
int mid = l + r >> 1;
if (pd(mid))
{
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
cout << ans;
return 0;
}