#include <bits/stdc++.h>
void swap(int *x, int *y) {
  int z;
  z = *x;
  *x = *y;
  *y = z;
}
int main(void) {
  int N, K;
  int p[1024];
  int i, m, n, l;
  int sum = 0;
  scanf("%d", &N);
  scanf("%d", &K);
  for (i = 0; i < N; i++) {
    scanf("%d", &p[i]);
  }
  for (m = 0; m < N; m++) {
    for (n = m + 1; n <= N; n++) {
      if (p[m] > p[n]) {
        swap(&p[m], &p[n]);
      }
    }
  }
  printf("並び替えると");
  for (i = 0; i < N; i++) {
    printf("%d ", p[i]);
  }
  printf("\n");
  for (l = 0; l < K; l++) {
    sum += p[l];
  }
  printf("%d", sum);
  return 0;
}
