const main = (input) => {
  const args = input.trim().split("\n");
  const [N, K] = args[0]
    .trim()
    .split(" ")
    .map((n) => parseInt(n, 10));

  const byAsc = (a, b) => a - b;
  const [...p] = args[1]
    .trim()
    .split(" ")
    .map((n) => parseInt(n, 10))
    .sort(byAsc);

  const bySum = (a, c) => a + c;
  const sum = p.filter((_, i) => i < K).reduce(bySum);

  console.log(sum);
};

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