#include <bits/stdc++.h>
int main(void) {
  int i, j, tmp;
  int price[1000];
  int variety, total, sum;
  scanf("%d", &total);
  scanf("%d", &variety);
  for (i = 0; i < total; ++i) {
    scanf("%d", &price[i]);
  }
  for (i = 0; i < total; ++i) {
    printf("%d ", price[i]);
  }
  for (i = 0; i < total; ++i) {
    for (j = i + 1; j < total; ++j) {
      if (price[i] > price[j]) {
        tmp = price[i];
        price[i] = price[j];
        price[j] = tmp;
      } else {
        printf("");
      }
    }
  }
  for (i = 0; i < total; ++i) printf("%d\n", price[i]);
  for (i = 0; i < variety - 1; i++) {
    sum = +price[i];
  }
  printf("%d", sum);
  return 0;
}
