// 思路:先找到最大的那个人,但是记得末尾k-1个不能找(不然人不够),然后第二人从第一个人后面开始找,也是找最大,同样的最后k-2个人不能找,以此类推即可

#include <cctype>
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;


void MainFunction(vector<int>& arr, int k){
    vector<int> selects;
    int selectIndex = -1;
    for (int i = 0; i < k; ++i){
        auto it = max_element(arr.begin() + selectIndex + 1, arr.end() - (k-i-1));
        int select = *it;
        selectIndex = (int)distance(arr.begin(), it);
        selects.push_back(select);
    }

    // 打印
    for (int i = 0; i < k ; i++){
        cout << selects[i] << " ";
    }

    return ;
}


int main() {
    string inputLine;
    getline(cin, inputLine);

    int n;
    cin >> n;

    istringstream iss(inputLine);
    vector<string> inputSting;
    string x;
    while (iss >> x) inputSting.push_back(x);

    for (string s : inputSting){
        for (char c : s){
            if (!isdigit(c)){
                cout << "error";
                return 0;
            }
        }
    }

    vector<int> inputInt;
    for (string s : inputSting){
        inputInt.push_back(stoi(s));
    }

    MainFunction(inputInt, n);

    return 0;
}