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