#include <bits/stdc++.h>
int main(void) {
  int n, k, ans = 0;
  int p[1001];
  scanf("%d %d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  int min, tmp;
  for (int i = 0; i < k; i++) {
    min = p[i];
    tmp = -1;
    for (int j = i + 1; j < n; j++) {
      if (min > p[j]) {
        min = p[j];
        tmp = j;
      }
    }
    if (tmp != i) {
      p[tmp] = p[i];
      p[i] = min;
    }
  }
  for (int i = 0; i < k; i++) {
    ans += p[i];
  }
  printf("%d\n", ans);
  return 0;
}
