import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	}
	
	public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	}
} import java.util.*; util.* java public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	}
	
	public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
		    arr[i] = sc.nextInt();
		} {
		    arr[i] = sc.nextInt();
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc System.out.println(solve(arr, k)) System.out.println System.out System System.out solve(arr, k) solve arr k String[] args args public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	} solve {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	} int n = arr.length; n arr.length arr arr.length if(n==0) {
	        return 0;
	    } n==0 n 0 {
	        return 0;
	    } return 0; 0 int sum = 0; sum 0 PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder()); heap new PriorityQueue(Collections.reverseOrder()) for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    } int i arr {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    } {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    } heap.add(i) heap.add heap i if(heap.size() > k) {
	            heap.remove();
	        } heap.size() > k heap.size() heap.size heap k {
	            heap.remove();
	        } heap.remove() heap.remove heap while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    } heap.size() > 0 heap.size() heap.size heap 0 {
	        sum += heap.peek();
	        heap.remove();
	    } sum += heap.peek() sum heap.peek() heap.peek heap heap.remove() heap.remove heap return sum; sum int[] arr arr int k k public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	}
	
	public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	}
} public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	}
	
	public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	}
} Main
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	}
	
	public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	}
}
