fun main(args: Array<String>) {
    // var numberTests = readLine()!!.toInt()
    // var results = mutableListOf<String>()

    // for (i in 0..numberTests-1) {
    var tmpLine = readLine()
    var tmps = tmpLine!!.split("\\s+".toRegex()).map {it.toInt()}
    val n = tmps[0]
    val k = tmps[1]
    
    tmpLine = readLine()
    val values = tmpLine!!.split("\\s+".toRegex()).map {it.toInt()} 
    var valuesSorted = mutableListOf<Int>()

    for (value in values) {
        valuesSorted.add(value)
        valuesSorted.sort()
        if (valuesSorted.size > k) valuesSorted = valuesSorted.dropLast(1) as MutableList<Int>
    }

    println(valuesSorted.sum())
}