全排列,next_permutation
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define sf scanf
#define pf printf
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define dbg(x) cerr << "Line:" << __LINE__ << " : " << #x << " = " << (x) << endl
#define nMax 1000000
#define ll long long
#define CLR(a) memset((a),0,sizeof((a)))
int n,m;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while(sf("%d%d",&n,&m)==2) {
vector<int> a(n);
rep(i,n) a[i]=i+1;
rep(i,m-1) next_permutation(a.begin(),a.end());
rep(i,n) {
if(i) pf(" ");
pf("%d",a[i]);
}pf("\n");
}
return 0;
}