import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); } Arrays.sort(a); long sum = 0; for (int i = 0; i < k; i++) { if (a[n-i-1] < 0) break; sum += a[n-i-1]; } System.out.println(sum); } }