import java.util.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = Integer.parseInt(scan.next()); int k = Integer.parseInt(scan.next()); int[] a = new int[n]; for(int i = 0;i < n; ++i){ a[i] = Integer.parseInt(scan.next()); } 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); } }