#include <bits/stdc++.h>
int main() {
  int n, k, tmp;
  scanf("%d%d", &n, &k);
  int num[n];
  for (int i = 0; i < n; i++) {
    num[i] = 0;
    scanf("%d", &num[i]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (num[i] > num[j]) {
        tmp = num[i];
        num[i] = num[j];
        num[j] = tmp;
      }
    }
  }
  for (int i = 0; i < n; i++) printf("%d\n", num[i]);
  int a = 0;
  for (int i = 0; i < k; i++) a += num[i];
  printf("%d\n", a);
}
