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(); int max = Integer.MIN_VALUE; PriorityQueue pq = new PriorityQueue<>(); for(int i = 0; i < n; i++) { int num = sc.nextInt(); max = Math.max(max, num); 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 == 0 ? max : sum); } }