#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  int i, j, min, minnum, tmp;
  int ans = 0;
  for (i = 0; i < N; i++) {
    cin >> p[i];
  }
  for (i = 0; i < N; i++) {
    min = p[i];
    minnum = i;
    for (j = i + 1; j < N; j++) {
      if (min > p[j]) {
        min = p[j];
        minnum = j;
      }
    }
    tmp = p[i];
    p[i] = p[minnum];
    p[minnum] = tmp;
  }
  for (i = 0; i < N; i++) {
    cout << p[i] << " ";
  }
  cout << endl;
  for (i = 0; i < K; i++) {
    ans += p[i];
  }
  cout << ans << endl;
}
