"use strict"

let inputs = ``
let enemyHp =[]
let x = 0

const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
})

reader.on('line', function(input) {
  inputs += input+` `
})

reader.on('close', function() {
  let items = inputs.trim().split(' ')
  
  for(let i = 0 ; i < items.length ; i=i+1){
    items[i] = items[i]|0
    if( i>=2 )enemyHp[i-2] = items[i]
  }

  enemyHp.sort(function(a,b){return (a < b ? 1 : -1)})

  for(let i = items[1]; i < enemyHp.length ; i=i+1){
    x += enemyHp[i]
  }
  console.log(x);
})