import java.util.Scanner object Main extends App { val sc = new Scanner(System.in) val n = sc.nextInt val k = sc.nextInt println(Array.fill(n)(sc.nextInt).filter(_ > 0).sorted.reverse.splitAt(k)._1.sum) }