function main(input) {
  let args = input.split(/\n/);
  let fruits = args[1].split(/\s/);
  let value = 0;
  function compareFunc(a, b) {
    return a - b;
  };
  fruits.sort(compareFunc);
  for (let i = 0;i < args[0].split(/\s/)[1];i++) {
    value += fruits[i] * 1;
  }
  console.log(value);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));