#include <bits/stdc++.h>
using namespace std;
int a[20000];
int main() {
  int sum = 0;
  int n, m, x;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
  }
  int j = 1;
  while (m > 0) {
    while ((a[j] > 0) && (m > 0)) {
      sum = sum + j;
      a[j]--;
      m--;
    }
    j++;
  }
  cout << sum;
  return 0;
}
