#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 tmp;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (p[j] < p[i]) {
        tmp = p[j];
        p[j] = p[i];
        p[i] = tmp;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ans += p[i];
    printf("%d ", p[i]);
  }
  printf("%d\n", ans);
  return 0;
}
