import java.util.Arrays; import java.util.Scanner; 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[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); Arrays.sort(a); int ans = a[n - 1]; for (int i = n - 2; i >= n - k; i--) { if (a[i] >= 0) { ans += a[i]; } } System.out.println(ans); } }