function main(input) {
  const array = input.trim().split("\n");
  const NK = array[0].trim().split(" ");
  let N = parseInt(NK[0]);
  let K = parseInt(NK[1]);
  let p = array[1].trim().split(" ");
  p.sort(function (a, b) {
    if (parseInt(a) < parseInt(b)) return -1;
    if (parseInt(a) > parseInt(a)) return 1;
    return 0;
  });
  let counter = 0;
  for (let i = 0; i < K; i++) {
    counter += parseInt(p[i]);
  }
  console.log(counter);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main("5 3\n50 100 80 120 80");
// main("1 1\n1000");
