function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const [n, k] = stdin.shift().split(' ').map(Number);
    const w = stdin.map(Number);

    let left = 0;
    let right = w.reduce((t, c) => t += c);

    if(k > 1) {
        while (right - left > 1) {
            const mid = Math.floor((left + right) / 2);

            if (n <= getBagNumWhenCapaIs(mid, k, w)) {
                right = mid;
            } else {
                left = mid;
            }
        }
    }
    console.log(k === 0 ? 0 : right);
}

function getBagNumWhenCapaIs(mx, numTrucks, bags) {
    let bagIdx = 0;
    for (let j = 0; j < numTrucks; j++) {
        let curWeight = 0;
        while (curWeight + bags[bagIdx] <= mx) {
            curWeight += bags[bagIdx];
            bagIdx++;
            if (bagIdx === bags.length) {
                return bags.length
            }
        }
    }
    return bagIdx;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


