#include <bits/stdc++.h>
using namespace std;
#define rw(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
#define ios ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define vi vector <ll>
vi cv;
ll n, m, k, i;
bool check(ll t) {
priority_queue<ll, vector<ll>, greater<ll>> may;
for (ll i = 1; i <= m; i++) may.push(0);
for (ll it : cv) {
ll tmp = may.top();
may.pop();
if (tmp + it > t) return false;
may.push(tmp + it);
}
return true;
}
ll binary (ll l, ll r) {
ll ans = 0;
while (l <= r) {
ll mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
return ans;
}
int main() {
ios;
cin >> n >> m;
ll x; ll s=0;
for (ll i = 1; i <= n; i++) {
cin >> x;
cv.push_back(x);
s+=x;
}
cout << binary(1,s);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgcncobmFtZSkgaWYgKGZvcGVuKG5hbWUiLmlucCIsICJyIikpICBmcmVvcGVuKG5hbWUiLmlucCIsICJyIiwgc3RkaW4pLCBmcmVvcGVuKG5hbWUiLm91dCIsICJ3Iiwgc3Rkb3V0KQojZGVmaW5lIGlvcyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgdmkgdmVjdG9yIDxsbD4KCnZpIGN2OwpsbCBuLCBtLCBrLCBpOwoKYm9vbCBjaGVjayhsbCB0KSB7CiAgICBwcmlvcml0eV9xdWV1ZTxsbCwgdmVjdG9yPGxsPiwgZ3JlYXRlcjxsbD4+IG1heTsKICAgIAogICAgZm9yIChsbCBpID0gMTsgaSA8PSBtOyBpKyspIG1heS5wdXNoKDApOwogICAgCiAgICBmb3IgKGxsIGl0IDogY3YpIHsKICAgICAgICBsbCB0bXAgPSBtYXkudG9wKCk7CiAgICAgICAgbWF5LnBvcCgpOwogICAgICAgIAogICAgICAgIGlmICh0bXAgKyBpdCA+IHQpIHJldHVybiBmYWxzZTsKICAgICAgICAKICAgICAgICBtYXkucHVzaCh0bXAgKyBpdCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQoKbGwgYmluYXJ5IChsbCBsLCBsbCByKSB7IAogICAgbGwgYW5zID0gMDsKICAgIHdoaWxlIChsIDw9IHIpIHsKICAgICAgICBsbCBtaWQgPSAobCArIHIpIC8gMjsKICAgICAgICBpZiAoY2hlY2sobWlkKSkgewogICAgICAgICAgICBhbnMgPSBtaWQ7CiAgICAgICAgICAgIHIgPSBtaWQgLSAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGwgPSBtaWQgKyAxOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBhbnM7IAp9CgppbnQgbWFpbigpIHsgCiAgICBpb3M7CiAgIAogICAgY2luID4+IG4gPj4gbTsKICAgIGxsIHg7IGxsIHM9MDsKICAgIGZvciAobGwgaSA9IDE7IGkgPD0gbjsgaSsrKSB7ICAgIAogICAgICAgIGNpbiA+PiB4OwogICAgICAgIGN2LnB1c2hfYmFjayh4KTsKICAgICAgICBzKz14OwogICAgfQoKICAgIGNvdXQgPDwgYmluYXJ5KDEscyk7CgogICAgcmV0dXJuIDA7Cn0K