#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;
int n, m, tem, res = 0;
string s;
bool st[N];
int cnt[N];
bool flag, op;
void dfs(int u)
{
if (flag) return;
if (u > n)
{
res++;
if (res == m + 1)
{
for (int i = 1; i <= n; i++) printf("%d ", cnt[i]);
flag = true;
return;
}
return;
}
for (int i = 1; i <= n; i++)
{
if (!res) i = s[u - 1] - '0';
if (!st[i])
{
st[i] = true;
cnt[u] = i;
dfs(u + 1);
st[i] = false;
}
}
}
int main()
{
scanf_s("%d%d", &n, &m);
for (int i = 1, x = 0; i <= n; i++) scanf_s("%d", &x), s += (x + '0');
dfs(1);
return 0;
}