const main = input => {
  const lines = input.trim().split(/\s|\n/).map(e => Number.parseInt(e))
  const [n, k, ...p] = lines
  return p.sort((a, b) => a - b).slice(0, k).reduce((a, c) => a + c, 0)
}; // Implement this function

console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8'))); // Common part