#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> max_profit(int N, int M, vector<int>& a) {
    vector<int> result(M, 0);
    for (int i = 0; i < M; i++) {
        int max_val = *max_element(a.begin(), a.end());
        result[i] = max_val;
        a.erase(remove(a.begin(), a.end(), max_val), a.end());
    }
    return result;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<int> result = max_profit(N, M, a);

    for (int i = 0; i < M; i++) {
        cout << result[i] << " ";
    }
    cout << endl;

    return 0;
}