#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int k, n;
  cin >> k >> n;
  int ans = 0;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < k; i++) {
    ans += A[i];
  }
  cout << ans << "\n";
}
