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[] juices = new int[n]; for(int i = 0 ; i < n ; i++){ juices[i] = sc.nextInt(); } int ans = 0; for(int i = 0 ; i < k ; i++){ int max = 0; int index = -1; for(int j = 0 ; j < n ; j++){ if(juices[j] > max){ max = juices[j]; index = j; } } if(max == 0){ break; } ans += max; juices[index] = -101; } System.out.println(ans); } }