#include <bits/stdc++.h>
int cmpnum(const void *n1, const void *n2) {
  if (*(long *)n1 > *(long *)n2) {
    return 1;
  } else if (*(long *)n1 < *(long *)n2) {
    return -1;
  } else {
    return 0;
  }
}
int main() {
  int N;
  scanf("%d", &N);
  int price[N];
  int K;
  scanf("%d", &K);
  for (int i = 0; i < K; ++i) {
    scanf("%d", &price[i]);
  }
  qsort(price, K, sizeof(int), cmpnum);
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += price[i];
  }
  printf("%d", ans);
}
