#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 9
vector<int> v;
int arr[MAX]{ 0 };
bool vis[MAX]{ 0 };
int n, m;
void dfs(int idx)
{
if (idx == m)
{
for (int i = 0; i < m; i++)
cout << arr[i] << " ";
cout << '\n';
return;
}
for (int i = 0; i < v.size(); i++)
{
if (!vis[i])
{
vis[i] = true;
arr[idx] = v[i];
dfs(idx + 1);
vis[i] = false;
}
}
}
int main()
{
cin >> n >> m;
v.resize(n);
for (int i = 0; i < v.size(); i++)
cin >> v[i];
sort(v.begin(), v.end());
dfs(0);
}