function main(input) {
  const inputs =input.split('\n')
  const [N, K] = inputs[0].split(' ').map(Number)
  const p = inputs[1].split(' ').map(Number)
  p.sort((a,b) => a > b ? 1 : -1)
  console.log(
    p.slice(0, K).reduce((h, e) => {
      return h + e
    }, 0)
  )
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())
