#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K;
  int p[1000];
  int m;
  int sum = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N - 1; j++) {
      m = p[j];
      if (p[j + 1] < m) {
        p[j] = p[j + 1];
        p[j + 1] = m;
      }
    }
  }
  for (int i = 0; i < N; i++) cout << p[i];
  cout << endl;
  for (int i = 0; i < K; i++) sum += p[i];
  cout << sum << endl;
  return 0;
}
