#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, tmp;
  priority_queue<int> Q;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    Q.push(-tmp);
  }
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += Q.top();
    Q.pop();
  }
  cout << ans << "\n";
  return 0;
}
