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