#include <bits/stdc++.h>
using namespace std;
int ans, n, m, a[10005];
int main()
{
cin >> n;
cin >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
do
{
ans++;
if (ans == m + 1)
{
for (int i = 1; i <= n - 1; i++)
cout << a[i] << " ";
cout << a[n] << endl;
break;
}
} while (next_permutation(a + 1, a + n + 1));
return 0;
}