#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, D;
  int SUM = 0;
  int S = 0;
  int j = 0;
  int a;
  vector<int> f(1001);
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    cin >> a;
    f.at(a) += 1;
  }
  for (int k = 0; k < 1001; k++) {
    if (j < D) {
      S = f.at(k) * k;
      SUM = S + SUM;
      j += f.at(k);
    }
  }
  cout << SUM << endl;
  return 0;
}
