fun main (args:Array<String>){
    val (_ , numOfBuyFruits)  = readLine()!!.split(" ").map(String::toInt)
    val valueList = readLine()!!.split(" ").map(String::toInt).sortedDescending()
    val valuePoint  = valueList[numOfBuyFruits-1]
    var sumValue = 0
    for (value in valueList) {
        if(value <= valuePoint){
            sumValue += value
        }
        break
    }
    print(sumValue)
}