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