(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 = [];
  for (let i = 0; i < k; i++) {
    t[i] = w.shift();
  }
  w.forEach(function(e) {
    let i = k-1;
    t[i] += e;
    t.sort((a, b) => b - a);
  });
  console.log(t[0]);
})();

