//config = {input: 'tmp', newline: '\r\n'}; // win
config = {input: '/dev/stdin', newline: '\n'}; // linux

fs = require('fs');
si = fs.createReadStream(config.input);

rl = require('readline').createInterface({input: si, output: process.stdout});

is_first = true;
n = 0;
k = 0;
w = [];
rl.on('line', function(line) {
  if (is_first) {
    ary = line.split(' ');
    n = parseInt(ary[0], 10);
    k = parseInt(ary[1], 10);
    is_first = false;
  } else {
    w.push(parseInt(line, 10));
    if (w.length === n) {
      rl.close();
      si.destroy();
    }
  }
});

rl.on('close', function() {
  var min, max = 1, mid;
  while (!is_loadable(n, k, w, max)) max *= 2;
  if (max === 1) {
    console.log(1);
    return;
  }
  min = max / 2;
  while (max - min > 1) {
    mid = Math.floor((max + min) / 2);
    if (is_loadable(n, k, w, mid)) max = mid;
    else min = mid;
  }
  console.log(max);
});

function is_loadable(n, k, w, P) {
  var i = 0, j = 0, sum = 0;
  while (i < n) {
    if (sum + w[i] <= P) {
      sum += w[i];
    } else {
      sum = w[i];
      j++;
    }
    i++;
  }
  if (sum !== 0) j++;
  if (sum > P) return false;
  return j <= k;
}