#include <bits/stdc++.h>
using namespace std;
int n, k, x, kk = 0, sum = 0;
priority_queue<int> pq;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    pq.push(x);
  }
  while (!pq.empty() && kk < k) {
    sum += pq.top();
    pq.pop();
    k++;
  }
  printf("%d", sum);
}
