#include <iostream>
#include <algorithm>
using namespace std;
const int N = 10010;
int a[N];
int n, k;
int main()
{
while(cin >> n >> k)
{
int m = 1;
for(int i = 0; i < n; i ++ ) a[i] = i + 1;
while(next_permutation(a, a + n))
{
m ++;
if(m == k) break;
}
for(int i = 0; i < n; i ++ )
{
if(i != n - 1) printf("%d ",a[i]);
else printf("%d\n",a[n - 1]);
}
}
return 0;
}