#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n, m, a[N];
bool check(int mid)
{
int tot = 1;
for (int i = 1; i <= m; i++)
{
int sum = 0;
while (sum + a[tot] + 1 <= mid)
{
sum += a[tot];
sum++;
tot++;
}
if (sum + a[tot] + 1 == mid + 1)
{
sum += a[tot];
tot++;
}
if (tot > n)
{
break;
}
}
if (tot > n)
{
return 1;
}
return 0;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie();cout.tie();
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int l = 1, r = 1e15;
while (l < r)
{
int mid = (l + r) / 2;
if (check(mid))
{
r = mid;
}
else
{
l = mid + 1;
}
}
cout << r;
return 0;
}