#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N;
  int p[1000];
  int tmp;
  int sum = 0;
  cin >> K >> N;
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N - 1; ++j) {
      if (p[i] > p[i + 1]) {
        tmp = p[j];
        p[j] = p[j + 1];
        p[j + 1] = tmp;
      }
    }
  }
  for (int i = 0; i < K; ++i) {
    sum += p[i];
  }
  cout << sum << endl;
  return 0;
}
