#include "iostream"
#include "set"
#include "algorithm"
using namespace std;
int main()
{
int n, m;
/*multiset<int> s;
multiset<int>::iterator it;*/
while (cin >> n >> m && m != 0 && n != 0)
{
int *a = new int[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a+n);
for (int i = 0; i < n; i += m)
{
if (i != 0)
cout << " ";
cout << a[i];
}
/*for (int i = 0; i < n; i++)
s.insert(a[i]);
int j;
for (it = s.begin(), j = 0; it != s.end(), j < s.size(); it++, j ++)
{
if (j % m == 0)
{
if (j != 0)
cout << " ";
cout << *it;
}
}*/
cout << endl;
}
}