function Main(input) {
  const inputArr = input.split(/\n| /);

  const n = parseInt(inputArr[0], 10);
  const k = parseInt(inputArr[1], 10);

  let pArr = [];
  for (let i = 0; i < n; i++) {
    pArr[i] = parseInt(inputArr[i + 2], 10);
  }

  pArr.sort(function (a, b) {
    if (a < b) {
      return -1;
    } else if (a > b) {
      return 1;
    } else {
      return 0;
    }
  });

  let sum = 0;
  for (let i = 0; i < k; i++) {
    sum += pArr[i];
  }

  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
