#include <bits/stdc++.h>
using namespace std;
int64_t i, j, k, l;
int main() {
  int n, k, s;
  cin >> n >> k;
  s = 0;
  int p[n];
  int a[101] = {0};
  for (i = 0; i < n; i++) {
    cin >> p[i];
    a[p[i]] += 1;
  }
  i = 0;
  while (k > 0) {
    if (a[i] != 0) {
      s += i;
      a[i] -= 1;
      k -= 1;
    } else {
      i += 1;
    }
  }
  cout << s;
  return 0;
}
