/*
num = q.top();
其余同队列
定义:
//priority_queue<int,vector<int>,less<int> > pque;//less<int> greater<int>后面不加括号
priority_queue<int,vector<int>,cmp> pque;
*/
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<queue>
using namespace std;
int n,m;
int num;
struct cmp
{
bool operator()(int &a,int &b)
{
return a<b;
}
};
priority_queue<int,vector<int>,cmp> que;
int main()
{
int i,j;
while(1){
cin>>n>>m;
if(n==0&&m==0)
break;
for(i=0;i<n;i++)
{
cin>>num;
que.push(num);
}
for(j=0;j<m;j++)
{
int top=que.top();
que.pop();
if(j==0) cout<<top;
else cout<<" "<<top;
}
cout<<endl;
}
return 0;
}