#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int main() {
  int p[1001] = {0};
  int k = 0, n = 0, tmp = 0, sum = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  for (int j = 0; j < n; j++) {
    for (int m = j + 1; m < j; m++) {
      if (p[j] < p[m]) {
        tmp = p[m];
        p[m] = p[j];
        p[j] = tmp;
      }
    }
  }
  for (int s = 0; s < k; s++) {
    sum += p[s];
  }
  printf("%d", sum);
}
