import java.util.*; public class Main { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); PriorityQueue pq = new PriorityQueue<>(); for(int i = 0; i < n; i++) { int num = sc.nextInt(); if(num > 0) pq.offer(num); if(pq.size() > k) pq.poll(); } int sum = 0; while(!pq.isEmpty()) sum += pq.poll(); System.out.println(sum); } }