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++) { pq.offer(sc.nextInt()); if(pq.size() > k) pq.poll(); } int sum = 0; while(!pq.isEmpty()) sum += pq.poll(); System.out.println(sum); } }