#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const ll FMAX = 2e18;
const int NMAX = 16e3;
ifstream fin("transport.in");
ofstream fout("transport.out");
int v[NMAX + 1];
bool is_possible(const int &n, const int &max_transports, const int &total_capacity) {
int current_volume_occupied = 0;
int total_transports = 1;
for (int i = 1; i <= n; i++) {
//fout << i << ' ' << total_transports << ' ' << current_volume_occupied << '\n';
if (current_volume_occupied + v[i] <= total_capacity) {
current_volume_occupied += v[i];
continue;
}
total_transports++;
current_volume_occupied = v[i];
if (current_volume_occupied > total_capacity)
return false;
}
return total_transports <= max_transports;
}
int get_truck_capacity(const int &n, const int &k, const int &minimum_capacity, const int &max_capacity) {
int left = minimum_capacity;
int right = max_capacity;
int ans = 0;
while (left <= right) {
int middle = (left + right) / 2;
if (is_possible(n, k, middle)) {
right = middle - 1;
ans = middle;
}
else
left = middle + 1;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
int minimum_capacity = 0;
int max_capacity = 0;
int n, k;
fin >> n >> k;
for (int i = 1; i <= n; i++) {
fin >> v[i];
minimum_capacity = max(minimum_capacity, v[i]);
max_capacity += v[i];
}
fout << get_truck_capacity(n, k, minimum_capacity, max_capacity) << '\n';
//fout << is_possible(n, k, 7) << '\n';
return 0;
}