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();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	}

} 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();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	} 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 PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder()); maxHeap new PriorityQueue<>(k, Collections.reverseOrder()) for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		} {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		} int val = sc.nextInt(); val sc.nextInt() sc.nextInt sc if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			} maxHeap.size() < k maxHeap.size() maxHeap.size maxHeap k {
				maxHeap.offer(val);
			} maxHeap.offer(val) maxHeap.offer maxHeap val {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			} if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				} val < maxHeap.peek() val maxHeap.peek() maxHeap.peek maxHeap {
					maxHeap.poll();
					maxHeap.offer(val);
				} maxHeap.poll() maxHeap.poll maxHeap maxHeap.offer(val) maxHeap.offer maxHeap val int ans = 0; ans 0 while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		} !maxHeap.isEmpty() maxHeap.isEmpty() maxHeap.isEmpty maxHeap {
			ans += maxHeap.poll();
		} ans += maxHeap.poll() ans maxHeap.poll() maxHeap.poll maxHeap System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	}

} 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();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	}

}
