#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, temp, price[1001] = {0};
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    price[temp]++;
  }
  int point = 0, sum = 0;
  for (int i = 0; point < k; i++) {
    while (price[i]) {
      sum += i;
      price[i]--;
      point++;
    }
  }
  cout << sum << endl;
  return 0;
}
