import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int calc(int k, int[] ws) {
    bool match(int limit) {
        int n = 0;
        int sum = 0;
        foreach (w; ws) {
            if (sum + w <= limit) {
                sum += w;
            }
            else {
                sum = w;
                n++;
                if (n > k)
                    return false;
            }
        }
        return n + 1 <= k;
    }

    int lo = ws.reduce!max;
    int hi = 10 ^^ 9;
    int ans = hi;
    while (lo <= hi) {
        int m = (lo + hi) / 2;
        if (match(m)) {
            ans = min(ans, m);
            hi = m - 1;
        }
        else {
            lo = m + 1;
        }
    }
    return ans;
}

void main() {
    auto nk = readints();
    int n = nk[0], k = nk[1];

    int[] ws;
    for (int i = 0; i < n; i++) {
        ws ~= readint();
    }
    writeln(calc(k, ws));
}