fun main() {
    val k = readLine()!!.split(' ')[1].toInt()
    var mink = 0
    var sum = 0
    val p = readLine()!!.split(' ').map { it.toInt() }
    for(i in p.indices) {
        if(i < k) {
            sum += p[i]
            if(mink < p[i]) mink = p[i]
        }
        else if(mink > p[i]){
            sum -= mink
            mink = p[i]
            sum += mink
        }
    }
    println(sum)
}