#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  sort(p.begin(), p.end());
  int sum = 0;
  for (int i = 0; i < k; ++k) sum += p[i];
  cout << sum << endl;
}
