fun main() { val (n, k) = readLine()!!.split(" ").map{it.toInt()} println(readLine()!!.split(" ").map{it.toInt()}.sorted().reversed().take(k).let{ if(it.first() < 0) it.first() else it.sumOf{it2 -> 0.coerceAtLeast(it2)} }) }