#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, a[1003] = {0}, ans = 0, k;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n - i - 1; j++)
      if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);
  for (i = 1; i <= n; i++) cout << a[i] << " ";
  for (i = 1; i <= k; i++) ans += a[i];
  cout << ans;
  return 0;
}
