(function main(){
  let lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n");
  let [n, k] = lines.shift().split(' ').map(Number);
  let w = lines.map(Number).sort((a, b) => b - a);

  if (k == 1) {console.log(w.reduce((p, c) => p + c, 0));return;}

  let t = [];
  let t2 = [];
  for (let i = 0; i < k; i++) {
    t[i] = w.shift();
    t2[i] = [t[i]];
  }

  w.forEach(function(e) {
    let i;
    for (i = 1; i < k; i++) {
      if (t[0] > t[i] + e) break;
    }
    i = i == k ? k - 1 : i;
    t[i] += e;
    t2[i].push(e);
    t.sort((a, b) => b - a);
    t2.sort((a, b) => b.reduce((p, c) => p+c,0) - a.reduce((p, c) => p+c,0));
  });
  console.log(t[0]);
})();

