#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N;
  cin >> K >> N;
  vector<int> vec(N);
  int money = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < K; i++) {
    money += vec.at(i);
  }
  cout << money << endl;
}
