#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k;
  cin >> n >> k;
  priority_queue<int> pq;
  for (int i = 0; i < n; i++) {
    int pp;
    cin >> pp;
    pq.push(pp);
  }
  int ans = 0;
  while (k) {
    ans += pq.top();
    pq.pop();
    k--;
  }
  cout << ans << endl;
  return 0;
}
