You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).

The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn is the number of permutations of length n with maximum possible value of f(p). The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.   In subproblem B1 (3 points), the constraint 1 ≤ n ≤ 8 will hold.  In subproblem B2 (4 points), the constraint 1 ≤ n ≤ 50 will hold.

Output n number forming the required permutation.

NoteIn the first example, both permutations of numbers {1, 2} yield maximum possible f(p) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.

#include <bits/stdc++.h>

using namespace std;

int n;

long long x;

int a[111];

int main() {

	scanf("%d %I64d", &n, &x);

	long long now = 1ll << (n - 2);

	int le = 1, ri = n;

	for (int i = 1; i < n; i ++) {

		if (x > now) x -= now, a[ri--] = i;

		else a[le++] = i;

		now >>= 1;

	}

	a[le] = n;

	for (int i = 1; i <= n; i ++) printf("%d%c", a[i], i == n ? '\n' : ' ');

	return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 50

ll p[maxn];
void cal(ll m, ll n, pair<ll, ll> pa, ll k)
{
	if(pa.first == pa.second)
	{
		p[pa.first] = k;
		return;
	}
	if(m <= (1LL<<(n - 2)))
	{
		p[pa.first] = k;
		cal(m, n - 1, make_pair(pa.first + 1, pa.second), k + 1);
	}
	else
	{
		p[pa.second] = k;
		cal(m - (1LL<<(n - 2)), n - 1, make_pair(pa.first, pa.second - 1), k + 1);
	}
}

int main()
{
	ll n, m, i;
	scanf("%I64d %I64d", &n, &m);
	cal(m, n, make_pair(0, n - 1), 1);
	for(i = 0; i < n; i++)
	{
		if(i)
			printf(" ");
		printf("%I64d", p[i]);
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define CLR(a) memset(a, 0, sizeof(a))
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define MOD 1000000007
#define fi first
#define sec second
#define pb push_back
#define rep(a, b) for(a = 0; a < b; a++)
#define rep2(a, b) for(a = 1; a <= b; a++)
#define all(a) a.begin(), a.end()
#define pq priority_queue
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m; cin >> n >> m;
	string str = "";
	for(ll i = 1; i <= n; i++)
		str += i+'0';
	// cout << str << endl;
	vector<pair<ll, string> > vv;
	do{
		vector<ll> v(n, 0);
		for(ll i = 0; i < n; i++)
			v[i] = str[i]-'0';
		ll lsum = 0;
		for(ll i = 0; i < n; i++)
		{
			ll minn = MOD;
			for(ll j = i; j < n; j++)
			{
				minn = min(minn, v[j]);
				lsum += minn;
			}
		}
		vv.pb({lsum, str});
	}while(next_permutation(str.begin(), str.end()));
	sort(all(vv));
	ll maxx = 0;
	for(auto a : vv)
		maxx = max(maxx, a.fi);
	vector<string> ve;
	// cout << maxx << endl;
	for(auto a : vv)
		if(a.fi == maxx)
			ve.pb(a.sec);
	for(ll j = 0; j < n; j++)
		cout << ve[m-1][j] << " ";
	cout << endl;
	return 0;
}

/*
    Author : RAJON BARDHAN
    AUST CSE 27th Batch
    All my programming success are dedicated to my love TANIA SULTANA RIMY

    ALGORITHM :
*/
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-8
#define PI 3.14159265358979323846
#define pb push_back
#define memo(a,b) memset(a,b,sizeof(a))
typedef long long ll ;
int arr[10],cn[1000000];
int main()
{
    //freopen("input.txt","r",stdin);
    int n , m , mx=-1 ;
    cin >> n >> m ;
    for(int i=1;i<=n;i++) arr[i] = i;
    int cnt = 0 ;
    int prev = -1 ;
    while( true )
    {
        int f = 0 ;
        for(int i=1;i<=n;i++)
        {
            int ans = 0 ;
            for(int j=i;j<=n;j++)
            {
                int T = 1000 ;
                for(int k=i;k<=j;k++) T = min(T,arr[k]);
                ans+=T;
            }
            f=f+ans;
        }
        cn[cnt]=f;
        mx=max(f,mx);
        cnt++;
        next_permutation(&arr[1],&arr[n+1]);
        if(cnt==40320) break ;
    }
    cnt = 0 ;
    for(int i=1;i<=n;i++) arr[i] = i;
    for(int i=0;;i++)
    {
        if(cn[i]==mx) cnt++;
        if(cnt==m)
        {
            for(int k=1;k<=i;k++) next_permutation(&arr[1],&arr[n+1]);
            break ;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i!=1) cout << ' ';
        cout << arr[i] ;
    }
    puts("");
    return 0;
}

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
//#include<unordered_map>
#include <set>
#include<string>
#include<string.h>
#include<fstream>
#include<stack>
#include<iomanip>
#include<bitset>
#include<cmath>
//#include<random>
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> P;
//#define mp make_pair
#define lson rt<<1
#define rson rt<<1|1
#define mid (l+r)>>1
#define mes(a) memset(a,0,sizeof a)
#define NO "NO"
#define YES "YES"
#define mp make_pair
#define pk push_back
#ifndef scanf
#define scanf scanf_s
#endif
#define flu cout.flush()
//#define mp make_pair
//long double pi = acos(-1);
//LL mod = (LL)1<<50;
//LL QPow(LL a, LL b) { LL ans = 1; while (b > 0) { if (b & 1)ans = ans % mod * a%mod; a = a % mod * a%mod; b >>= 1; }return ans; }
/*LL inf = (LL)1 << 30;
double eps = 1e-8;
//LL mod = 1e9 + 7;
LL fac[5002];
LL fac_1[5002];
LL inv[5002];
void getInv()
{
	inv[1] = 1;
	for (int i = 2; i <= 5000; i++)
		inv[i] = (mod - mod / i)*inv[mod%i] % mod;
}
void init1()
{
	fac[0] = 1;
	fac_1[0] = 1;
	fac_1[1] = 1;
	for (int i = 1; i <= 5000; i++)
		fac[i] = fac[i - 1] * i%mod, fac_1[i] = inv[i] * fac_1[i - 1]%mod;
}
LL C(int n, int m)
{
	if (m<0 || m>n)return 0;
	return fac[n] * fac_1[n - m] % mod*fac_1[m] % mod;
}*/
LL gcd(LL x, LL y)
{
	if (x == 1 || y == 1)
		return 1;
	else
	{
		if (x == 0)return y;
		if (y == 0)return x;
		if (x%y == 0)return y;
		if (y%x == 0)return x;
		if (x > y)return gcd(x%y, y);
		else return gcd(x, y%x);
	}
}
/*
int sign(LL x)
{
	if (x == 0)return 0;
	if (x > 0)return 1;
	return -1;
}
LL toInt(string str)
{
	LL ans = 0;
	for (int i = (str[0] == '-'); i < str.size(); i++)
	{
		ans *= 10;
		ans += str[i] - '0';
	}
	if (str[0] == '-')
		ans = -ans;
	return ans;
}*/
//整数转字符串
string toString(LL a)
{
	if (a == 0)return "0";
	string temp = "";
	if (a < 0)
		temp.push_back('-');
	LL tp = a;
	while (tp)
	{
		temp.push_back('0' + tp % 10);
		tp /= 10;
	}
	string temp2 = temp;
	for (int ii = 0; ii < temp.size(); ii++)
	{
		temp[ii] = temp2[temp.size() - 1 - ii];
	}
	return temp;
}
/*ll fpow(ll a, ll b, ll c) { a %= c; ll ans = 1; while (b > 0) { if (b & 1)ans = ans * a%c; b >>= 1; a = a * a%c; }return ans; }
bool IsQuadraticResidue(ll a, ll p) {//判断a是否为p的二次剩余 p是素数
	return fpow(a, (p - 1) >> 1, p) == 1;
}
ll Shanks(ll a, ll p) {//求解二次同余方程x^2=a(mod p) p是素数
	if (a == 0)return 0;
	ll q = p - 1, e = 0;
	while (!(q & 1))q >>= 1, e++;
	static mt19937_64 rd(time(0));
	ll n = rd() % (p - 1) + 1;//随机选取p的一个非二次剩余，若p为定值，n也可为定值
	while (IsQuadraticResidue(n, p))n = rd() % (p - 1) + 1;
	ll z = fpow(n, q, p), y = z, r = e, x = fpow(a, (q - 1) >> 1, p), b = a * x%p*x%p;
	x = a * x%p;
	while (b != 1) {
		ll temp = b * b%p, m = 1;
		while (temp != 1)(temp *= temp) %= p, m++;
		if (m == r)return -1;
		ll t = y;
		//rep(i, 1, r - m - 1)
		for(int i=1;i<=r-m-1;i++)
			(t *= t) %= p;
		y = t * t%p, r = m % p, x = x * t%p, b = b * y%p;
	}
	return x;
}
const int mx = 1e3 + 5;
//int arr[mx][mx];
LL rd() {
	LL ans = 0; char last = ' ', ch = getchar();
	while (!(ch >= '0' && ch <= '9'))last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')ans = ans * 10 + ch - '0', ch = getchar();
	if (last == '-')ans = -ans; return ans;
}*/
LL inf = INT_MAX;
const int maxn = 8e4 + 5;
/*const int maxm = 5e1 + 5;
LL n, m, s, t, cnt = 0;
int head[maxn];
int cur[maxn];
int dis[maxn];
bool vis[maxn];
int minfee = 0;
struct edge
{
	int v, w, nx, f;//w=cost
}eds[maxm * 2];
inline void add(int u, int v, int flow, int w)
{
	eds[cnt].v = v;
	eds[cnt].w = w;//cost
	eds[cnt].f = flow;
	eds[cnt].nx = head[u];
	head[u] = cnt++;
}*/
/*bool spfa(int u, int v)
{
	for (int i = 0; i < maxn; i++)dis[i] = inf;
	mes(vis);
	dis[u] = 0;
	deque<int>d;
	d.push_back(u);
	vis[u] = 1;
	while (!d.empty())
	{
		int uu = d.front();
		d.pop_front();
		vis[uu] = 0;
		for (int i = head[uu]; i != -1; i = eds[i].nx)
		{
			int vv = eds[i].v;
			int w = eds[i].w;
			int f = eds[i].f;
			if (f&&dis[vv] > dis[uu] + w)
			{
				dis[vv] = dis[uu] + w;
				if (!vis[vv])
				{
					if (!d.empty() && dis[vv] < dis[d.front()])
						d.push_front(vv);
					else d.push_back(vv);
				}
			}
		}
	}
	return dis[t] != inf;
}*/
/*bool bfs()
{
	memset(dis, -1, sizeof dis);
	dis[1] = 0;
	queue<int>q;
	q.push(s);
	while (!q.empty())
	{
		int r = q.front();
		q.pop();
		for (int i = head[r]; i != -1; i = eds[i].nx)
		{
			int j = eds[i].v;
			if (dis[j] == -1 && eds[i].w)
			{
				dis[j] = dis[r] + 1;
				q.push(j);
			}
		}
	}
	return dis[t] != -1;
}
int dfs(int u, int flo)
{
	if (u == n)return flo;
	int detla = flo;
	for (int i = head[u]; i != -1; i = eds[i].nx)
	{
		int v = eds[i].v;
		if (dis[v] == (dis[u] + 1) && (eds[i].w > 0))
		{
			int d = dfs(v, min(detla, eds[i].w));
			eds[i].w -= d;
			eds[i ^ 1].v += d;
			detla -= d;
			if (detla == 0)break;
		}
	}
	return flo - detla;
}
int dini()
{
	int ans = 0;
	while (bfs())
	{
		mes(vis);
		ans += dfs(s, inf);
	}
	return ans;
}*/
//int cnt[maxn];
//map<P, P>ans;
int cnt = 0;
int head[maxn], dep[maxn], fa[maxn][22];
LL dis[maxn];
struct edge
{
	int v, nx;
	LL val;
}es[maxn << 1];
void add(int u,int v,int w)
{
	es[cnt].v = v;
	es[cnt].nx = head[u];
	es[cnt].val = w;
	head[u] = cnt++;
}
void dfs0(int u, int f,LL ds)
{
	dis[u] = ds;
	//cout << "dfs0:" << u << " " << ds << endl;
	for (int i = head[u]; i != -1; i = es[i].nx)
	{
		int v = es[i].v;
		if (v == f)continue;
		dfs0(v, u, ds + es[i].val);
	}
}
void dfs(int u, int f)
{
	dep[u] = dep[f] + 1;
	fa[u][0] = f;
	for (int i = 1; (1 << i) <= dep[u]; i++)
	{
		fa[u][i] = fa[fa[u][i - 1]][i - 1];
	}
	for (int i = head[u]; i != -1; i = es[i].nx)
	{
		int v = es[i].v;
		if (v != f)
			dfs(v, u);
	}
}
int lca(int a, int b)
{
	if (dep[a] > dep[b])
		swap(a, b);
	for (int i = 20; i >= 0; i--)
		if (dep[a] <= dep[b] - (1 << i))
			b = fa[b][i];
	if (a == b)return a;
	for (int i = 20; i >= 0; i--)
	{
		if (fa[a][i] == fa[b][i])
			continue;
		else a = fa[a][i], b = fa[b][i];
	}
	return fa[a][0];
}
bool rot[maxn];
int cnt1[60];
int cnt2[60];
int cnt3[60][60];
int ans[100];
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ifstream in("Text.txt");
	LL n, m, s,t;
	LL d;
	cin >> n>>m;
	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	int lef = 1, rig = n;
	int ct = 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (m > ((LL)1 << (i-1)))
		{
			ans[rig--] = ct++;
			m -= (LL)1 << (i-1);
		}
		else ans[lef++] = ct++;
	}
	for (int i = 1; i <= n; i++)
		cout << ans[i] << " ";
//	system("pause");
	return 0;
}

#include <cstdio>

int main() {
    for(long long n, m; ~scanf("%lld%lld", &n, &m);) {
        int a[n], l = 0, r = n-1;
        long long p = 1; p <<= n-2;

        for(int i = 1; i <= n; i++, p>>=1)
            if(m > p) a[r--] = i, m -= p;
            else      a[l++] = i;

        for(int i = 0; i < n; i++)
            printf("%d%c", a[i], i==n-1?'\n':' ');
    }
}

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    int nums[n];
    for (int i = 0; i < n; i++) {
        nums[i] = i + 1;
    }

    int maxfp = 0;
    do {
        int fp = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j++) {
                int min = 55;
                for (int k = i - 1; k <= j - 1; k++) {
                    if (nums[k] < min) min = nums[k];
                }
                fp += min;
            }
        }
        if (fp > maxfp) maxfp = fp;
    } while (next_permutation(nums,nums+n) );

    sort(nums,nums+n);

    int i = 0;
    do {
        int fp = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j++) {
                int min = 55;
                for (int k = i - 1; k <= j - 1; k++) {
                    if (nums[k] < min) min = nums[k];
                }
                fp += min;
            }
        }

        if (fp == maxfp) {
            if (++i == m) {
                for (int j = 0; j < n - 1; j++) {
                    cout << nums[j] << " ";
                }
                cout << nums[n - 1] << endl;
                break;
            }
        }
    } while (next_permutation(nums,nums+n) );

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int sum(vector<int>& v){
	int s = 0, n = v.size();
	for (int i = 0; i < n; i++){
		for (int j = i; j < n; j++){
			int mi = 100;
			for (int k = i; k <= j; k++){
				mi = min(mi, v[k]);
			}
			s += mi;
		}
	}
	return s;
}

int main(){
//	freopen("input.txt", "r", stdin);

	ios::sync_with_stdio(false);

	int m, n;
	cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i < v.size(); i++) v[i] = i + 1;

	int maxs = 0;
	do {
		maxs = max(maxs, sum(v));
	}while(next_permutation(v.begin(), v.end()));

	do {
		if (maxs == sum(v)) m--;
	}while(m && next_permutation(v.begin(), v.end()));

	for (int i: v) cout << i << ' ';

	return 0;
}

#include <iostream>

using namespace std;
int n;
long long m;
int soln[51];
long long mr = 0;

int main() {
    cin >> n >> m;
    --m;
    for(int k = 1; k < n; ++k) {
        mr = mr * 2 + (m & 1);
        m >>= 1;
    }

    int i = 1, j = n;
    for(int k = 1; k <= n; ++k) {
        if(mr & 1)
            soln[j--] = k;
        else
            soln[i++] = k;
        mr >>= 1;
    }

    for(int k = 1; k <= n; ++k)
        cout << soln[k] << ' ';
    cout << endl;

}

#include <iostream>
#include <vector>

int main()
{
    long long N, M;
    std::cin >> N >> M;

    std::vector<int> v(N + 1);
    auto i = 1;
    auto j = N;
    long long k = 1LL << (N-1);

    auto next = 1;
    while (i <= j) {
        if (M <= k/2) {
            v[i++] = next++;
        } else {
            v[j--] = next++;
            M -= k/2;
        }

        k /= 2;
    }

    for (auto i = 1u; i < v.size(); ++i)
        std::cout << v[i] << " ";
    std::cout << std::endl;

    return 0;
}

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC target ("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int n, m;
	cin >> n >> m;
	int cnt = 0, prv = 1;
	vi v;
	while(1) {
		int cur = 0;
		if(!v.empty()) {
			cur = v.back();
		}
		for(int i = prv; i <= n; i++) {
			if(i == n) {
				cnt++;
			}
			else {
				cnt += (1LL << (n - i - 1));
			}
			if(cnt >= m) {
				v.pb(i);
				prv = i + 1;
				cnt -= (1LL << (n - i - 1));
			}
		}
		if(!v.empty() && cur == v.back()) {
			break;
		}
	}
	bool done[n + 1] = {0};
	for(int i : v) {
		done[i] = 1;
	}
	for(int i = n; i >= 1; i--) {
		if(!done[i]) {
			v.pb(i);
		}
	}
	for(int i : v) {
		cout << i <<  " ";
	}

	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<bitset>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll fastpo(ll a, ll x){
    if(x == 0) return 1;
    if(x == 1) return a;
    ll y = fastpo(a, x/2);
    if(x%2 == 0){
        return y*y;
    }
    return y*y*a;
}

ll inv(ll a, ll M){
    return fastpo(a, M-2);
}

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    if (g != 1)
        return -1;
    else
    {
        ll res = (x%m + m) % m;
        return res;
    }
}

ll gcd(ll a, ll b){
    if(a == 0){
        return b;
    }
    return gcd(b%a, a);
}

ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

int main(){
    // clock_t time_req;
    // time_req = clock();
    ll n, m;
    cin>>n>>m;
    m--;
    string s = "";
    for(int i=0; i<n-1; i++){
        s = s + "0";
    }
    for(int i=0; i<n-1; i++){
        int r = m%2;
        if(r == 1ll){
            s[i] = '1';
        }
        m = m/2;
    }
    reverse(s.begin(), s.end());
    // cout<<s<<endl;
    vector<ll> ans(n);
    ll l = 0, r = n-1;
    for(int i=0; i<n-1; i++){
        if(s[i] == '0'){
            ans[l] = i+1;
            l++;
        }
        else{
            ans[r] = i+1;
            r--;
        }
    }
    ans[l] = n;
    for(int i=0; i<n; i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    // time_req = clock()-time_req;
    // cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>a;
int f()
{
    int ans=0;
    for(int i=0;i<n;i++)
    {
       int mini=a[i];
       for(int j=i;j<n;j++)
       {
           mini=min(mini,a[j]);
           ans+=mini;
       }
    }
    return ans;
}
int main()
{
    int m;
    cin>>n>>m;
    a.resize(n);
    for(int i=0;i<n;i++)
        a[i]=i+1;
    int maxi=f();
    int kol=1;
    while(kol!=m)
    {

        next_permutation(a.begin(),a.end());
        if (f()==maxi)
            {kol++; /*for(int i=0;i<n;i++)
        cout<<a[i]<<' ';cout<<endl;*/}
    }
    for(int i=0;i<n;i++)
        cout<<a[i]<<' ';
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<string.h>
#include<queue>
#include<map>
#include<algorithm>
#define M 1000000007
using namespace std;
vector<int> as;
int a[100];
int vis[100];
void findans(int n,int m)
{
    int i,j,k,sum=0,ans=0,p,q,msum=0;
    //cin>>n>>m;
    string w;
    for(i=1;i<=n;i++)
    as.push_back(i);
    for(i=0;i<n;i++)
        {
            for(j=i;j<n;j++)
            {
               msum+=as[i];
            }
        }
        q=0;//cout<<msum<<endl;
    do
    {
        sum=0;
        for(i=0;i<n;i++)
        {

            for(j=i;j<n;j++)
            {
                p=100;
                for(k=i;k<=j;k++)
                {
                    p=min(p,as[k]);

                }
                sum+=p;
            }
        }
        //cout<<sum<<endl;
        w="";
        if(sum==msum)
        {
            ans++;

               //cout<<sum<<endl;
               q++;
               if(q==m)
               {

               for(i=0;i<n;i++)
               cout<<as[i]<<" ";
               return ;
               }

        }

    }
    while(next_permutation(as.begin(),as.end()));
    //cout<<ans<<endl;

}
main()
{
    long long int i,j,k,n,m,till,total,curr,p;
    cin>>n>>m;
    if(n<=8)
    {
        findans(n,m);
        return 0;
    }
    total=pow(2.0,(double)n-1);
    if(m==total)
    {
        for(i=n;i>=1;i--)
        cout<<i<<" ";
        return 0;
    }
    if(m==1)
    {
        for(i=1;i<=n;i++)
        cout<<i<<" ";
        return 0;

    }
    i=1;
    while(1)
    {
        if(m<=total/2)
        {
            a[0]=i;
            break;
        }
        else
        {
            i++;
            m-=total/2;
            total/=2;
        }

    }
    vis[i]=1;
    total/=2;
    j=1;
    curr=a[0]+1;
    while(m!=0&&j!=n-1&&curr!=n+1&&total!=0)
    {

        if(m<=total/2)
        {
            a[j]=curr;
            j++;
            total/=2;
            vis[curr]=1;
            curr=a[j-1]+1;

        }
        else
        {
            curr++;
            m-=total/2;
            total/=2;
        }
        //cout<<j<<" "<<total<<" "<<curr<<" "<<m<<endl;

    }

    if(curr==n+1)
    {
        for(i=j;i<n;i++)
        {
            for(p=n;p>=1;p--)
            {
                if(vis[p]==0)
                {
                    a[i]=p;
                    vis[p]=1;
                    break;
                }

            }

        }

    }
    for(i=0;i<n;i++)
    cout<<a[i]<<" ";
    return 0;
    //cout<<a[0];

}

#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define SZ(v) (int)(v).size()
#define ALL(v) (v).begin(), (v).end()
#define FOR(it, v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

typedef long long LL;

const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int maxn = 100;

int n;
LL m;
LL l[maxn];
LL r[maxn];
int v[maxn];
int res[maxn];
bool used[maxn];

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;
	l[0] = 1;
	r[0] = 1;
	l[1] = 1;
	r[1] = 1;
	v[1] = n;
	int cur = n - 1;
	for (int i = 2; i <= n; i++){
		l[i] = r[i - 1] + 1;
		r[i] = r[i - 1] * 2;
		v[i] = cur--;
	}
	cur = n;
	while (m > 0){
		for (int i = 1; i <= n; i++){
			if (l[i] <= m && m <= r[i]){
				res[cur--] = v[i];
				m -= (r[i - 1]);
				used[v[i]] = true;
				break;
			}
		}
	}
	for (int i = n; i >= 1; i--){
		if (!used[i]){
			res[cur--] = i;
		}
	}
	for (int i = 1; i <= n; i++){
		cout << res[i] << " ";
	}

	return 0;
}

 /*
 LANG : C++
 */
 # include <iostream>
 # include <cstdio>
 # include <cstdlib>
 # include <algorithm>
 # include <cstring>
 # include <map>
 # include <set>
 # include <vector>

 # define FOR(xxx, yyy, zzz) for(long long xxx = yyy; xxx <= zzz; ++xxx)
 # define f first
 # define s second
 # define pb push_back
 # define mp make_pair

 using namespace std;

 typedef long long ll;

 ll a[60], f[60];
 ll n, m;

 set < pair<ll, ll> > st;

 void rec (ll x) {
     st.clear ();
     if (x == n + 1) {
        FOR (i, 1, n)
        cout << a[i] << ' ';
        return;
     }
    /* FOR (i, 1, n)
     cout << a[i] << ' ';
     cout << endl;*/
     FOR (i, 1, n) {
        if (!a[i]) {
            ll pr = i;
            while (a[pr] == 0 && pr >= 1ll) pr --; pr ++;
            ll nx = i;
            while (a[nx] == 0 && nx <= n) nx ++; nx --;
            st.insert (mp ((nx - i + 1) * (i - pr + 1), i));
         //   cout << (nx - i + 1) * (i - pr + 1) << ' ' << i << ' ' << x << endl;
        }
     }
    // cout << f[n - x] << endl;
    // if (pos == 0) pos ++;
    ll pos = 1;

    if (n - x - 1 >= 0)
     pos = (m + f[n - x - 1] - 1ll) / f[n - x - 1];
    else pos = 1;
    if (n - x - 1 >= 0 && m >= f[n - x - 1])
        m -= f[n - x - 1];
    if (m == 0) m = f[n - x - 1];
     //cout << pos << endl;
     for (set < pair<ll, ll> > :: iterator it = st.begin (); it != st.end (); ++it) {
        pos --;
        if (pos == 0)  {
       //         cout << (it -> s) << endl;
            a[(it -> s)] = x;
            rec (x + 1);
            break;
        }
     }
 }

 int main () {
     cin >> n >> m;
     f[0] = 1;
     FOR (i, 1, n)
     f[i] = 2ll * f[i - 1];
     rec (1);
 }

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int64 n, m;
int mas[3000];
int num[51];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> m;
    m--;
    int64 in = 0;
    for(int i = 0; i < n; ++i)
    {
        int64 t = (1ll << (n - 2 - i));
        if (t > m)
        {
            mas[in++] = i;
            num[i] = 1;
        }
        else
            m -= t;
    }
    for(int i = n - 1; i >= 0; --i)
    {
        if (num[i])
            continue;
        mas[in++] = i;
    }
    for(int i = 0; i < n; ++i)
        cout << mas[i] + 1 << ' ';
    return 0;
}

/*
Just Another Source code by -
 __        ______
 \ \      / /  _ \ _ __ __ _  __ _  ___  _ __
  \ \ /\ / /| | | | '__/ _` |/ _` |/ _ \| '_ \
   \ V  V / | |_| | | | (_| | (_| | (_) | | | |
    \_/\_/  |____/|_|  \__,_|\__, |\___/|_| |_|
                             |___/
(0_0)
*/
#include<bits/stdc++.h>
#define pii pair<int,int>
#define VP vector< pii >
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define S2(x,y) scanf("%d%d",&(x),&(y))
#define SL(x) scanf("%lld",&(x))
#define SL2(x) scanf("%lld%lld",&(x),&(y))
#define P(x) printf("%d\n",(x))
#define FF first
#define SS second
#define cbits(x) __builtin_popcount(x)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define sz(x) (int)x.size()
using namespace std;
//int dx[]={1,0,0,-1},dy[]={0,1,-1,0};

typedef long long ll;

const int MAX = 1000003;
const int MOD = 1000000007;

ll n, m;
vector<int> ans(52,0);
void solve(){
	cin >> n >> m;
	ll tm = m;
	int l = 1, r = n, curr = 1;
	while(tm > 0){
		if( n > 1 and (1ll<<(n - 1 - curr)) >= tm){
			ans[l] = curr;
			++l;
		}
		else{
			ans[r] = curr;
			--r;
			tm = tm - (1ll<<(n-1-curr));
		}
		++curr;
	}
	for(int i = 1; i <= n; ++i){
		cout << ans[i] <<" ";
	}
	cout << "\n";
}

int main(){
int t = 1;
//cin>>t;
//scanf("%d", &t);
while(t--){

	solve();

}
return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define LL long long
const int MAX=1<<30;
using namespace std;
int n,m,a[110],t,maxa=0;
struct ww
{
    int b[110];
};
ww w[1000];
bool cmp(ww A,ww B)
{
    for(int i=1;i<=n;i++)
        if(A.b[i]!=B.b[i])
        return A.b[i]<B.b[i];
}
int main()
{
  // freopen("in.txt","r",stdin);
  cin>>n>>m;
  for(int i=1;i<=n;i++)
    a[i]=i;
  do
  {
      int p=0;
      for(int i=1;i<=n;i++)
          {

              for(int j=i;j<=n;j++)
              {
                  int mina=1<<30;
                  for(int k=i;k<=j;k++)
                  if(a[k]<mina)
                    mina=a[k];
                     p+=mina;
              }
          }
      if(p>maxa)
      {
          maxa=p;
          t=0;
          for(int i=1;i<=n;i++)
          w[t].b[i]=a[i];
          continue;
      }
      if(p==maxa)
      {
          t++;
          for(int i=1;i<=n;i++)
          w[t].b[i]=a[i];
      }
  }while(next_permutation(a+1,a+n+1));
  sort(w,w+t,cmp);
  /*for(int j=0;j<t;j++)
  {
      for(int i=1;i<=n;i++)
    cout<<w[j].b[i]<<" ";
    cout<<endl;
  }*/
   for(int i=1;i<=n;i++)
    cout<<w[m-1].b[i]<<" ";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define MAXN 1123456
#define int long long
#define pb push_back

//m-esima perm de tamanho n
vector<int> find(int n,int m,int mini){
    if(n==1)return {mini};
    int val=1ll<<(n-2);
    //cout<<"val eh "<<val<<" "<<m<<endl;
    if(m<=val){
        //cout<<"entrou no if"<<endl;
        vector<int> a1={mini};
        vector<int> a2=find(n-1,m,mini+1);
        for(auto x:a2)a1.pb(x);
        return a1;
    }
    else{
        //cout<<"entrou no else"<<endl;
        vector<int> ans=find(n-1,m-val,mini+1);
        ans.pb(mini);
        return ans;

    }
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

    int n,m;
    cin>>n>>m;
    vector<int> ans=find(n,m,1ll);
    for(auto x:ans)cout<<x<<" ";
    cout<<endl;

    return 0;

}

#include <bits/stdc++.h>
using namespace std;

#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define fi                first
#define se                second
#define vc                vector
#define pii               pair<bint,bint>
#define msi               map<string,bint>
#define mii               map<bint,bint>
#define psi               pair<string,bint>
#define pis               pair<bint,string>
#define endl              "\n"
#define rep(i,a,b)        for(bint i=a;i<b;i++)
#define repe(i,a,b)       for(bint i=a;i<=b;i++)
#define bac(i,a,b)        for(bint i=a;i>b;i--)
#define bace(i,a,b)       for(bint i=a;i>=b;i--)
#define fast               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define smallbint          bint
#define bint              long long int
#define float             long double
#define mod1              (bint)(1e9 + (bint)7)
#define mod2              (bint)998244353
#define pi                (float)3.14159265358979323846
//#define hs                100006
#define inf               (bint)1e18
#define ninf              (bint)((bint)-1*(1e18))

#define DECIMAL(n)        std::cout << std::fixed << std::setprecision(n)
#define SORT(v)           sort(all(v))
#define RSORT(v)          sort(all(v),greater<bint>())
#define REVERSE(v)        reverse(ALL(v))

#define init(x,a)         memset(x,a,sizeof(x))
#define trav(a, x)        for(auto& A : x)
#define display(x)        trav(A,x) cout<<A<<" "; cout<<endl
#define pow(i,n)          (bint)pow((bint)i,n)
#define pow2(n)           ((bint)1<<n)
#define sz(x)             (bint)x.size()

typedef std::priority_queue<bint, std::vector<bint>, std::greater<bint> > min_pq;

template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {
    out<<a.fi<<" "<<a.se;
    return out;
}

template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {
    in>>a.fi>>a.se;
    return in;
}

inline string inttos(bint a){std::stringstream soso; soso<<a; return soso.str();}
inline bint stoint(const std::string &s) {std::stringstream soso; soso << s; long long x; soso >> x; return x;}
inline std::string inttobin(bint x) {return std::bitset<10>(x).to_string();}

void swp(bint &a, bint &b){
    auto temp=a;
    a=b;
    b=temp;
}

void solve()
{
    bint n,m;
    cin>>n>>m;
    vc<bint> v(n);
    rep(i,0,n){
        v[i]=-1;
    }
    bint lo = 0;
    bint hi = pow2(n-1);
    bint x =0;
    bint y = n-1;
    bint t = 1;
    while(lo+1<hi){
        bint mid = (lo+hi)/2;
        if(mid<m){
            v[y] = t;
            t++;
            y--;
            lo = mid;
        }
        else{
            v[x] = t;
            x++;
            t++;
            hi = mid;
        }
    }
    rep(i,0,n){
        if(v[i]==-1)
            v[i]=n;
    }
    display(v);

}

#warning: correct the global array value !!
/* -------------------------------------------------------
1.      CHECK IF THE SIZE OF THE GLOBAL ARRAYS ARE CORRECT
2.      CHECK FOR bintEGER OVERFLOW
3.      CHECK FOR INDEX OUT OF BOUNDS
4. 		IF DIVIDING A NUMBER CHECK IF DENM CAN BE 0
                    -------------------
*/

signed main(){
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    bint q=1;
    //cin>>q;
    rep(i,0,q){
        solve();
    }

    return 0;
}

#include <cstdio>

typedef long long ll;

ll n, m;

void f(int i) {
  if (i == n || m == 1) {
    for (int j = i; j <= n; ++j)
      printf("%d ", j);
  } else {
    ll aux = 1ll << (n-i-1);
    if (aux >= m) {
      printf("%d ", i);
      f(i+1);
    } else {
      m -= aux;
      f(i+1);
      printf("%d ", i);
    }
  }
}

int main() {
  scanf("%I64d %I64d", &n, &m);
  f(1);
  puts("");
  return 0;
}

//.......................................IN THE NAME OF GOD............................................//
//................................... CODE BY : SADEGH MAHDAVI........................................//

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define F(i,a,b) for(ll i=(a) ; i<=(b) ; i++)
using namespace std;
typedef long long ll;
typedef long double ld;

ll a[100];

ll pw(ll n){
	if(n==0) return 1;
	if(n==1) return 2;
	ll t=pw(n/2);
	return t*t*pw(n%2);
}

ll f(ll n,ll m,ll mn,ll mx,ll p){
	if(n==1){
		a[mn]=p+1;
		return 0;
	}
	if(m<=pw(n-2)){
		a[mn]=p+1;
		return f(n-1,m,mn+1,mx,p+1);
	}
	else{
		a[mx]=p+1;
		return f(n-1,m-pw(n-2),mn,mx-1,p+1);
	}
}

int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

ll n,m;
cin>>n>>m;
f(n,m,0,n-1,0);
F(i,0,n-1){
	cout<<a[i]<<" ";
}

return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    long long int n, m;
    while( cin>>n && cin>>m )
    {
        vector<int> head, tail;
        long long int one = 1;
        for(int i=1; i<=n; i++)
        {
            if( m>( one<<(n-i-1) ) )
            {
                m -= one<<(n-i-1);
                tail.push_back(i);
            }
            else
                head.push_back(i);
        }
        for(int i=0; i<head.size(); i++)
            cout<<head[i]<<" ";
        for(int i=tail.size()-1; i>=0; i--)
            cout<<tail[i]<<" ";
    }

    return 0;
}

#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>

#define mk make_pair
#define pb push_back
#define FOR(I,A,N) for (int (I)=(A); (I) < (N); ++(I))
#define REP(I,N) FOR(I,0,N)

using namespace std;

int cnt(vector<int>&a){
	int res = 0;
	REP(i,a.size()) {
		int mn = a[i];
		FOR(j,i,a.size()){
			mn = min(mn, a[j]);
			res+=mn;
		}
	}
	return res;
}

int main () {
	int n, m;
	cin >> n >> m;
	m--;
	vector<int> a(n);
	REP(i,n)a[i]=i+1;
	int mx = cnt(a);
	while(next_permutation(a.begin(), a.end())) mx = max(mx, cnt(a));
	while(m){
		if (mx == cnt(a))
			m--;
		next_permutation(a.begin(), a.end());
	}
	while(cnt(a) < mx) next_permutation(a.begin(), a.end());
	cout << a[0];
	FOR(i,1,n)cout<<' ' << a[i];
    return 0;
}

#include <bits/stdc++.h>

#define x0 abc
#define y0 ABC
#define x1 abcd
#define y1 ABCD
#define xn abcde
#define yn ABCDE

#define l_b lower_bound
#define u_b upper_bound

#define fi first
#define se second
#define m_p make_pair

#define p_b push_back
#define po_b pop_back

#define ld long double
#define ll long long

#define MAXLL 1000000000000000000LL
#define MAXINT 2000000000

#define MINLL -1000000000000000000LL
#define MININT -2000000000

#define P acos(-1)

#define endl '\n'

#define OUT cout << "-------" << endl;

using namespace std;

vector <ll> ans;

string s;

ll n, m, i;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;

    m--;

    while (m > 0) {
        if (m % 2 == 0)
        s += "L";
        else s += "R";

        m /= 2;
    }

    while (s.size() < n - 1) s += "L";

    for (i = n - 2; i >= 0; i--)
        if (s[i] == 'L') ans.p_b(s.size() - i);

    ans.p_b(n);

    for (i = 0; i < n - 1; i++)
        if (s[i] == 'R') ans.p_b(s.size() - i);

    for (i = 0; i < ans.size() - 1; i++) cout << ans[i] << " ";

    cout << ans[ans.size() - 1] << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define maxn int(2e6 + 12)
#define maxb int(2e6 + 12)
#define inf int(1e9 + 7)
#define linf ll(1e18 + 12)
#define eps 1e-7
#define mp make_pair
#define pb push_back
#define fn "b"
#define f first
#define s second

template<typename T>
T min(T a, T b, T c)
{
 return min(a, min(b, c));
}

template<typename T>
T max(T a, T b, T c)
{
 return max(a, max(b, c));
}

vector <int> v;
multimap <ll, vector <int>> s;
int n, m;

ll get()
{
 ll ans = 0ll;
 for (int l = 0; l < n; l++)
  for (int r = l; r < n; r++)
  {
   ll now = v[l];
   for (int k = l; k <= r; k++)
    now = min(now, ll(v[k]));
   ans += now;
  }
 return ans;
}

int main()
{
 scanf("%d%d", &n, &m);
 for (int i = 1; i <= n; i++)
  v.pb(i);
 ll maxx = -inf;
 do
 {
  ll ans = get();
  maxx = max(maxx, ans);
  s.insert(mp(ans, v));
 } while(next_permutation(v.begin(), v.end()));

 auto it = s.lower_bound(maxx);
 int t = 1;
 for (; it != end(s) && t < m; it++, t++);
 v = it -> s;
 for (int i = 0; i < n; i++)
  printf("%d ", v[i]);
}

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<bool> vb;

int main(){
ll n, m;
        cin >> n >> m;
        vi vec;
        ll k=1;
        stack<int> ans;
        bool used[111];
        memset(used,0,sizeof(used));
        for(int i = n; i>0; i-- )
        {
                int j = n;
                k=1;
                while( k < m ) {
                        k*=2;
                        j--;
                        while(j>0 &&used[j])j--;
                }
                while(j>0&&used[j])j--;
                used[j]=1;
                ans.push(j);
                m -= k/2;
        }

        while( !ans.empty() )
        {
                cout << ans.top() << " ";
                ans.pop();
        }
        cout << endl;

        return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,i;
    long long m;
    cin>>n>>m;
    m--;
    int a[n]={0},perm[n],beg=0,end=n-1;
    for(i=n;i>=2;i--)
    {
        a[i-2]=m%2;
        m/=2;
    }
    for(i=0;i<n;i++)
        if(a[i])
            perm[end--]=i+1;
        else
            perm[beg++]=i+1;
    for(i=0;i<n;i++)
        cout<<perm[i]<<' ';
}
//hellobig_tq

#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

int n, m;
bool used[200];
vector <vector <int> > perms;
vector <int> ress;

void gen(vector <int> cur)
{
    if (cur.size() == n)
    {
        perms.push_back(cur);
    }
    else
    {
        for (int i = 1; i <= n; i++)
        {
            if (!used[i])
            {
                cur.push_back(i);
                used[i] = true;
                gen(cur);
                cur.pop_back();
                used[i] = false;
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    vector <int> cur;
    gen(cur);
    for (int i = 0; i < perms.size(); i++)
    {
        cur = perms[i];
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                int mini = 1000000000;
                for (int k = i; k <= j; k++)
                {
                    if (cur[k] < mini)
                    {
                        mini = cur[k];
                    }
                }
                res += mini;
            }
        }
        ress.push_back(res);
    }
    vector <int> sr = ress;
    sort(sr.begin(), sr.end());
    int fp = sr.back();
    int pos = 1;
    vector <int> ans;
    for (int i = 0; i < perms.size(); i++)
    {
        if (ress[i] == fp)
        {
            if (pos == m)
            {
                ans = perms[i];
                break;
            }
            pos++;
        }
    }
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int N;
long long K;
int ans[100];

void solve(long long k, long long total, int lo, int hi, int offset) {
    if (lo > hi) return ;
    if (lo == hi) {
        ans[lo] = offset;
        return ;
    }
    int cnt = 0;
    long long t = total/2;
    while (k >= t && t) {
        k -= t;
        t /= 2;
        ++cnt;
    }
    ans[lo] = offset + cnt;
    for (int i = 0; i < cnt; ++i)
        ans[hi - i] = offset + i;
    solve(k, t, lo + 1, hi - cnt, offset + cnt + 1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> K;
    solve(K-1, 1LL << (N - 1), 0, N - 1, 0);
    for (int i = 0; i < N; ++i)
        cout << ans[i]+1 << " ";

    return 0;
}

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string>

#define N 55
#define M 105
#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 100000000
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b)

using namespace std;

ll nn,mm;
ll tt;
ll ans[N];

void ini()
{
    tt=1ll<<(nn-1);
}

void fun(ll now,ll tot,ll m,ll st,ll en)
{
    ll te=tot/2;
    if(st==en){
        ans[st]=now;return;
    }
    if(m<=te){
        ans[st]=now;
        fun(now+1,te,m,st+1,en);
    }
    else{
        ans[en]=now;
        fun(now+1,te,m-te,st,en-1);
    }
}

void solve()
{
    fun(1,tt,mm,1,nn);
}

void out()
{
    printf("%I64d",ans[1]);
    ll i;
    for(i=2;i<=nn;i++){
        printf(" %I64d",ans[i]);
    }
    printf("\n");
}

int main()
{
    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
    //scanf("%d",&T);
    //for(int ccnt=1;ccnt<=T;ccnt++)
   // while(T--)
    //scanf("%d%d",&n,&m);
    while(scanf("%I64d%I64d",&nn,&mm)!=EOF)
    {
        ini();
        solve();
        out();
    }
    return 0;
}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int,int> pt;
typedef pair<long long ,long long> ptl;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<vector<vector<long long>>> vvvl;
typedef vector<pair<int, int>> vpt;
typedef vector<pair<long long, long long>> vptl;
typedef vector<string> vs;
typedef set<int> si;
typedef set<long long> sl;
typedef unordered_set <int> usi;
typedef unordered_set <long long> usl;
typedef multiset<int> msi;
typedef multiset<long long> msl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
template <typename T>
using indexed_set = tree<T, null_type, less<T>,
	rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key: The number of items in a set that are strictly smaller than k
// find_by_order: It returns an iterator to the ith largest element
//Anubhaw Bhalotia https://github.com/anubhawbhalotia
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) x.begin(), x.end()
#define f(i,s,n) for(int i=s;i<n;i++)
#define fe(i,s,n) for(int i=s;i<=n;i++)
#define fr(i,s,n) for(int i=s;i>n;i--)
#define fre(i,s,n) for(int i=s;i>=n;i--)
#define watch1(x) cout <<(#x)<<" = "<<(x)<< endl
#define watch2(x, y) cout<<(#x)<<" = "<<(x)<<" "<<(#y)<<" = "<<(y)<<endl
#define watch3(x, y, z) cout<<(#x)<<" = "<<(x)<<" "<<(#y)<<" = "<<(y)<<" "<<\
	(#z)<<" = "<<z<<endl
#define log1(x) cout<<x<<endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
const int MOD = 998244353;
string getDecToBin(ll a)
{
	string s = "";
	while(a)
	{
		s += (a % 2 == 1) ? '1' : '0';
		a /= 2;
	}
	return s;
}
int solution(int tc)
{
	ll n, m;
	cin>>n>>m;
	m--;
	string b = getDecToBin(m);
	deque <int> q;
	int x = n;
	q.push_front(x--);
	for(auto i : b)
	{
		if(i == '1')
		{
			q.push_front(x--);
		}
		else
		{
			q.push_back(x--);
		}
	}
	while(x > 0)
	{
		q.push_back(x--);
	}
	while(!q.empty())
	{
		cout<<q.back()<<" ";
		q.pop_back();
	}
	cout<<endl;
	return 1;
}
void testCase()
{
	int tc = 1;
	// cin>>tc;
	f(i, 0, tc)
	{
		solution(i + 1);
		// cout<<"Case #"<<i + 1<<": "<<solution(i + 1)<<endl;
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    testCase();
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
typedef long long LL;
typedef pair<int,int>pil;
int num[50],b[50005][10];
int n,m;
int solve()
{
    int sum=0;
    REPF(i,1,n)
    {
        REPF(j,i,n)
        {
            int minn=0x3f3f3f3f;
            REPF(k,i,j)
                minn=min(minn,num[k]);
            sum+=minn;
        }
    }
    return sum;
}
int main()
{
    while(cin>>n>>m)
    {
        REPF(i,1,n)  num[i]=i;
        int maxx=0,cnt=0,sum;
        do
        {
            sum=solve();
            maxx=max(maxx,sum);
            b[++cnt][0]=sum;
            REPF(i,1,n)  b[cnt][i]=num[i];
        }while(next_permutation(num+1,num+1+n));
        sum=0;
        for(int i=1;i<=cnt;i++)
        {
            if(b[i][0]==maxx)  sum++;
            if(sum==m)
            {
                for(int j=1;j<=n;j++)
                    cout<<b[i][j]<<" ";
                cout<<endl;
                break;
            }
        }
    }
    return 0;
}

/*
    Author : RAJON BARDHAN
    AUST CSE 27th Batch
    All my programming success are dedicated to my love TANIA SULTANA RIMY

    ALGORITHM :
*/
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-8
#define PI 3.14159265358979323846
#define pb push_back
#define memo(a,b) memset(a,b,sizeof(a))
typedef long long ll ;
int arr[10],cn[1000000];
int main()
{
    //freopen("input.txt","r",stdin);
    int n , m , mx=-1 ;
    cin >> n >> m ;
    for(int i=1;i<=n;i++) arr[i] = i;
    int cnt = 0 ;
    int prev = -1 ;
    while( true )
    {
        int f = 0 ;
        for(int i=1;i<=n;i++)
        {
            int ans = 0 ;
            for(int j=i;j<=n;j++)
            {
                int T = 1000 ;
                for(int k=i;k<=j;k++) T = min(T,arr[k]);
                ans+=T;
            }
            f=f+ans;
        }
        cn[cnt]=f;
        mx=max(f,mx);
        cnt++;
        next_permutation(&arr[1],&arr[n+1]);
        if(cnt==40320) break ;
    }
    cnt = 0 ;
    for(int i=1;i<=n;i++) arr[i] = i;
    for(int i=0;;i++)
    {
        if(cn[i]==mx) cnt++;
        if(cnt==m)
        {
            for(int k=1;k<=i;k++) next_permutation(&arr[1],&arr[n+1]);
            break ;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i!=1) cout << ' ';
        cout << arr[i] ;
    }
    puts("");
    return 0;
}

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define _114day ""

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e5 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

  ll n, m;
  bool used[N];

  void calc(bool ok = 1, int last = 0, ll cur = 1ll << (n - 1)) {
    if (!ok) {
      per(i, n, 1)
        if (!used[i]) cout << i << ' ';
      ioi
    }

    ll can = max(1ll, cur / 2);
    rep(i, last + 1, n) {
      if (can >= m) {
        used[i] = 1;
        cout << i << ' ';
        calc(ok, i, can);
      }
      m -= can;
      can /= 2;
      can = max(can, 1ll);
    }

    calc(0, last, cur);
  }
int main() {
  #ifndef _114day
    freopen (_114day".in", "r", stdin);
    freopen (_114day".out", "w", stdout);
  #endif

  cin >> n >> m;
  calc();
  ioi
}

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
int main(){
    int ans[51];
    long long int n,k;
    scanf("%I64d %I64d",&n,&k);
    long long int m;
    m=pow(2,n-1);
   int bot_now=1;
   int top_now=n;
   int i;
   long long int a;

   a=m/2;
   for (i=1;i<=n;i++){
        m=m/2;
    if(k>a){
        ans[top_now]=i;
        top_now--;
        a=a+m/2;
    }else{
        ans[bot_now]=i;
        bot_now++;
        a=a-m/2;
    }

   }
   for (i=1;i<=n;i++){
        if (i<n)printf("%d ",ans[i]);
        else printf("%d",ans[i]);
   }
    return 0;
}

#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	unsigned long long m;
	cin >> n >> m;

	int ret[50];
	int tmp = n;

	int l = 0,
		r = n-1;
	m--;
	for (int i = 1; i <= n; ++i) {
		if (m >= (1LL << (n-i-1))) {
			// cout << 1 << ' ';
			ret[r--] = i;
			m -= (1LL << (n-i-1));
		} else {
			// cout << 0 << ' ';
			ret[l++] = i;
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << ret[i] << " ";
	}
	cout << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int n, m;
long long a[100][100];
int ans[100];

void prettify(int x, int n) {
    for (int i = 0; i < n; i++)
        if (ans[i] >= x)
            ans[i]++;
}

void get_ans(int n, long long k) {
    long long last = 0;
    int n1 = n;
    for (int i = 1; i < n; i++) {
        last += a[n][i];
        if (last >= k) {
            n1 = i;
            last -= a[n][i];
            break;
        }
    }
    last = k - last;
    ans[n] = n1;
    if (n1 == n) {
        for (int i = 1; i <= n; i++)
            ans[i] = i;
        return;
    }
    else {
        long long s = 0;
        for (int i = 1; i < n1; i++)
            s += a[n - 1][i];
        get_ans(n - 1, s + last);
        prettify(n1, n);
    }
}

int main()
{
    cin >> n >> m;
    a[1][1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j < i; j++) {
            for (int k = j; k <= i - 1; k++)
                a[i][j] += a[i - 1][k];
        }
        a[i][i] = 1;
    }
    get_ans(n, m);
    for (int i = n; i >= 1; i--)
        cout << ans[i] << ' ';

    return 0;
}

#include<bits/stdc++.h>

typedef long long ll;
typedef std::pair<ll,ll> pi;

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0);
#define se second
#define fi first
#define pb push_back
#define ALL(v) (v).begin(),(v).end()

int main()
{
    fastIO

    std::vector<std::vector<int>> maxSum;
    std::vector<int> v;
    int n,m;
    std::cin>>n>>m;
    for (int i=1;i<=n;++i)
        v.pb(i);
    int cmp=INT_MIN;
    do{
        int sum=0;
        for (int i=0;i<n;++i)
            for (int j=i;j<n;++j)
                sum+=*std::min_element(v.begin()+i,v.begin()+j+1);
        cmp=std::max(cmp,sum);
        if (sum==cmp) maxSum.pb(v);

    }
    while (std::next_permutation(ALL(v)));
    for (int x:maxSum[m-1]) std::cout<<x<< ' ';
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int i,k,t,ans[10005];
	long long n,m;
	scanf("%I64d %I64d",&n,&m);
	k=1;
	t=n;
	for(i=1;i<=n;i++)
	{
		if(m>(1LL<<(n-1-i)))
		{
			ans[t--]=i;
			m=m-(1LL<<(n-1-i));
		}
		else
		{
			ans[k++]=i;
		}

	}
	for(i=1;i<=n;i++)
	printf("%d ",ans[i]);
}

#pragma warning (disable : 4996)
#pragma comment(linker, "/STACK:36777216")

#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <assert.h>
#include <stack>
#include <algorithm>
#include <ios>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <sstream>
#include <map>
#include <memory.h>
#include <stdio.h>
#include <cassert>
#include <string.h>
#include <deque>

#define forn(i , n) for (int i = 0; i < n; ++i)
#define down(i, n) for (int i = n - 1; i >= 0; --i)

using namespace std;

typedef unsigned long long int u64;
typedef long long int i64;
typedef vector<int> vint;
typedef vector<i64> vi64;
typedef pair<int, int> pint;
typedef pair<i64, i64> pi64;

#define FILE_NAME "file"
#define CONTEST "seq"
#define M_PI 3.14159265358979323846

double sqr(double a)
{
    return a * a;
}

const i64 inf = 100000000000000000LL;

#define MOD 10000000000007

struct Node
{
    vector<pint> nbr;
    int used;

};

vector<vint> ans;
i64 n, m;

vint c;
int l = 0, r;

vint solve(int i, i64 m)
{
    if (i == n)
    {

        return c;
    }
    i64 can = n - i - 1;
    can = 1 << can;

    if (m * 2 >= can)
    {
        c[r--] = i;
        return solve(i + 1, m - can / 2);
    }
    else
    {
        c[l++] = i;
        return solve(i + 1, m);
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(15);

#ifdef FILE_INPUT
    freopen(FILE_NAME ".in", "r", stdin);
    freopen(FILE_NAME ".out", "w", stdout);
#endif
    cin >> n >> m;
    r = n - 1;
    c.resize(n);
    auto p = solve(0, m-1);
    forn(i, p.size())
    {
        cout << p[i] + 1 << " ";
    }

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pp;
typedef unsigned long long ull;
#define FOR(i, n) for(int i = 0; i < int(n); i++)
#define FORAB(i, a, b) for(int i = int(a); i <= int(b); i++)
#define FORTR(it, container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define what_is(x) cerr<< #x <<" = "<<x<<endl;
#define inp(x) cin>>x
#define outi(x) cout<<x
#define out(x) cout<<x<<endl
#define popcount(x) __builtin_popcount(x)
#define gcd(x,y) __gcd(x,y)
const int inf = 1e9;
const long long MAXINT_64 = numeric_limits<ll>::max();
const long long MININT_64 = numeric_limits<ll>::min();
const long double PI = ld(3.1415926535897932384626433832795);

void calc(int n){
	int arr[51];
	FOR(i,n){
		arr[i] = i+1;
	}
	int totalsummax = 0;
	int index = 0;
	do{
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		totalsummax = max(totalsum, totalsummax);
	}while(next_permutation(arr, arr+n));
	int z = 0;
	do{
		index++;
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		if(totalsum==totalsummax){
			FOR(i,n) cout<<arr[i]<<" "; cout<<" = "<<totalsum<<" "<<index<<endl;
		}
	}while(next_permutation(arr, arr+n));
	cout<<"z = "<<z<<endl;
}
void calc1(int n, int m){
	int arr[51];
	FOR(i,n){
		arr[i] = i+1;
	}
	int totalsummax = 0;
	int index = 0;
	do{
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		totalsummax = max(totalsum, totalsummax);
	}while(next_permutation(arr, arr+n));
	int z = 0;
	do{
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		if(totalsum==totalsummax){
			index++;
			if(index == m){
				FOR(i,n) cout<<arr[i]<<" "; cout<<" = "<<totalsum<<" "<<index<<endl;
				return;
			}
		}
	}while(next_permutation(arr, arr+n));
	cout<<"z = "<<z<<endl;
}

vector<int> solve(ll n, ll m){
	if(n == 1){
		vector<int> answer = {1};
		return answer;
	}
	if(n == 2){
		if(m == 1){
			vector<int> answer = {1,2};
			return answer;
		}
		else{
			vector<int> answer = {2,1};
			return answer;
		}
	}
	ll mid = pow(2, n-2);
	vector<int> answer;
	if(m <= mid){
		answer = solve(n-1,m);
		FOR(i,answer.size())
			answer[i] += 1;
		answer.insert(answer.begin(), 1);
	}
	else{
		answer = solve(n-1,m-mid);
		FOR(i,answer.size())
			answer[i] += 1;
		answer.pb(1);
	}
	return answer;
}

int main(){
    ios::sync_with_stdio(false);
    ll n,m;
//    calc(2);
//    calc(3);
//    calc(4);
//    calc(5);
//    calc(10);
    inp(n); inp(m);
//    calc(n,m);
    vector<int> answer = solve(n,m);
    FOR(i,answer.size()){
    	cout<<answer[i]<<" ";
    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
int n, m;
ll f(vector<int> a){
    ll S = 0;
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j++) {
            int mn = INT_MAX;
            for (int l = i; l <= j; l++){
                mn = min(mn, a[l]);
            }
            S += mn;
        }
    }
    return S;
}
int main()
{
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = i + 1;
    }
    vector<vector<int> > perm;
    int i = 0;
    ll mx = -INT_MAX;
    do {
        ll to = f(a);
        if (to>mx) {
            perm.clear();
            mx = to;
        }
        if (to == mx){
            perm.push_back(a);
        }
    } while (next_permutation(a.begin(),a.end()));
    for (int i = 0; i < perm[m - 1].size(); i++) {
        cout << perm[m - 1][i] << " ";
    }
}

#include<bits/stdc++.h>

using namespace std;

#define sf scanf
#define pf printf
#define ll long long
#define fr(I,M,N) for(I=M;I<=N;I++)
#define fr_(I,M,N) for(I=M;I>=N;I--)
#define re return
#define sfn cin>>n
#define pb push_back
#define ins insert
#define sz(X) X.size()
#define xx first
#define yy second

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int i,j,x,n,k,a,b,c,d,e,cnt=0,temp,i1,i2,i3,i4,i5,i6,i7,i8,i9,sum=0,t,mn,bal;
    cin>>n>>k;
    vector<int>v;
    fr(i,1,n)
    {
        v.pb(i);
        fr(j,0,n-i)
        sum+=i;
    }
    if(n==2)
        {
            if(k==1)
                cout<<"1 2";
            else
                cout<<"2 1";
            re 0;
        }
    for(i9=0;i9<9 && cnt<k;i9++)
    {
    for(i8=0;i8<8 && cnt<k;i8++)
    {
    for(i7=0;i7<7 && cnt<k;i7++)
    {
    for(i6=0;i6<6 && cnt<k;i6++)
    {
    for(a=0;cnt<k && a<5;a++)
        {
            for(b=0;b<4 && cnt<k;b++)
            {
            for(c=0;c<3 && cnt<k;c++)
            {
                for(d=0;d<2 && cnt<k;d++)
                {
                    for(e=0;e<1 && cnt<k;e++)
                    {

                    t=0;
                    vector<int> s;
                    s=v;
                    if(n>8 && i9!=0)
                    {
                        for(j=0;j<i9;j++)
                        {
                            temp=s[n-(9-i9)-j];
                            s[n-(9-i9)-j]=s[n-(9-i9)-j-1];
                            s[n-(9-i9)-j-1]=temp;
                        }
                    }
                    if(n>7 && i8!=0)
                    {
                        for(j=0;j<i8;j++)
                        {
                            temp=s[n-(8-i8)-j];
                            s[n-(8-i8)-j]=s[n-(8-i8)-j-1];
                            s[n-(8-i8)-j-1]=temp;
                        }
                    }
                    if(n>6 && i7!=0)
                    {
                        for(j=0;j<i7;j++)
                        {
                            temp=s[n-(7-i7)-j];
                            s[n-(7-i7)-j]=s[n-(7-i7)-j-1];
                            s[n-(7-i7)-j-1]=temp;
                        }
                    }
                    if(n>5 && i6!=0)
                    {
                        for(j=0;j<i6;j++)
                        {
                            temp=s[n-(6-i6)-j];
                            s[n-(6-i6)-j]=s[n-(6-i6)-j-1];
                            s[n-(6-i6)-j-1]=temp;
                        }
                    }
                    if(n>4 && a!=0)
                    {
                        for(j=0;j<a;j++)
                        {
                            temp=s[n-(5-a)-j];
                            s[n-(5-a)-j]=s[n-(5-a)-j-1];
                            s[n-(5-a)-j-1]=temp;
                        }
                    }
                    if(n>3 && b!=0)
                    {
                        for(j=0;j<b;j++)
                        {
                            temp=s[n-(4-b)-j];
                            s[n-(4-b)-j]=s[n-(4-b)-j-1];
                            s[n-(4-b)-j-1]=temp;
                        }
                    }
                    if(n>2 && c!=0)
                    {
                        for(j=0;j<c;j++)
                        {
                            temp=s[n-(3-c)-j];
                            s[n-(3-c)-j]=s[n-(3-c)-j-1];
                            s[n-(3-c)-j-1]=temp;
                        }
                    }
                    if(n>2 && d!=0)
                    {
                        for(j=0;j<d;j++)
                        {
                            temp=s[n-(2-d)-j];
                            s[n-(2-d)-j]=s[n-(2-d)-j-1];
                            s[n-(2-d)-j-1]=temp;
                        }
                    }

                    fr(i,0,n-1)
                    {
                        mn=n+1;
                        fr(j,i,n-1)
                        {
                            mn=min(mn,s[j]);
                            t+=mn;
                        }
                    }
                    //cout<<t<<" "<<sum<<endl;
                    if(cnt==k-1 && t==sum)
                    {
                        cout<<s[0];
                        fr(i,1,n-1)
                        cout<<" "<<s[i];
                        re 0;
                    }

                    //cout<<t<<" "<<sum<<endl;
                    if(t==sum)
                    cnt++;
                }
                }
            }
            }
        }
    }
    }
    }
    }
}

#include<bits/stdc++.h>
#define mod 1000000007
#include<bits/stdc++.h>
#define mod 1000000007
#define pp pair<ll,ll>
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define big 100000000000000000
using namespace std;

ll n,m,arr[100];

void ans(ll arr[],ll in1,ll in2,ll lo,ll hi,ll m){
	if(in1 > in2 || lo > hi || m <= 0)
		return;
	if(m == 1){
		for(ll i=in1,j=lo;i<=in2 && j<=hi;i++,j++)
			arr[i] = j;
		return;
	}
	if(m == 1<<(hi-lo)){
		for(ll i=in1,j=hi;i<=in2 && j>=lo;i++,j--)
			arr[i] = j;
		return;
	}
	else if((1<<(hi-lo-1)) < m){
		arr[in2] = lo;
		m -= (1<<(hi-lo-1));
		ans(arr,in1,in2-1,lo+1,hi,m);
	}
	else{
		arr[in1] = lo;
		ans(arr,in1+1,in2,lo+1,hi,m);
	}
}
int main(){
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(0);

	cin>>n>>m;
	ans(arr,1,n,1,n,m);

	for(ll i=1;i<=n;i++)
		cout<<arr[i]<<" ";

	return 0;
}

#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>

#define mk make_pair
#define pb push_back
#define FOR(I,A,N) for (int (I)=(A); (I) < (N); ++(I))
#define REP(I,N) FOR(I,0,N)

using namespace std;

int cnt(vector<int>&a){
	int res = 0;
	REP(i,a.size()) {
		int mn = a[i];
		FOR(j,i,a.size()){
			mn = min(mn, a[j]);
			res+=mn;
		}
	}
	return res;
}

int main () {
	int n, m;
	cin >> n >> m;
	m--;
	vector<int> a(n);
	REP(i,n)a[i]=i+1;
	vector<int> b(n);
	for (int i = 0; i < n  && 2*i+1 <= n; ++i) b[i] = 2*i+1;
	for (int j = n-1, i=2; j >=0 && i <= n; i+=2, j--) b[j]=i;
	int mx = cnt(b);
	while(m){
		if (mx == cnt(a))
			m--;
		next_permutation(a.begin(), a.end());
	}
	while(cnt(a) < mx) next_permutation(a.begin(), a.end());
	cout << a[0];
	FOR(i,1,n)cout<<' ' << a[i];
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>

using namespace std;

typedef long long Int;

Int count(int len) {
  return 1ll << (len-1);
}

Int func(vector<int> p) {
  int n = p.size();

  Int f = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      int m = n + 1;
      for (int k = i; k <= j; ++k) {
        m = min(m, p[k]);
      }
      f += m;
    }
  }
  return f;
}

vector<vector<int>> compute(int n) {
  vector<int> p(n);
  for (int i = 0; i < n; ++i) { p[i] = i+1; }
  Int best_f = 0;
  do {
    best_f = max(best_f, func(p));
  } while(next_permutation(p.begin(), p.end()));

  vector<vector<int>> order;
  for (int i = 0; i < n; ++i) { p[i] = i+1; }

  do {
    if (func(p) == best_f) {
      order.push_back(p);
    }
  } while(next_permutation(p.begin(), p.end()));

  return order;
}

vector<int> solve(int n, Int m) {
  vector<int> p(n);

  int left = 0;
  int right = n-1;

  Int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    Int t = count(right - left);
    if (t > m) {
      p[left++] = i;
    } else {
      m -= t;
      p[right--] = i;
    }
  }

  return p;
}

void output(vector<int> p) {
  for (int x: p) {
    cout << x << " ";
  }
  cout << endl;
}

int main() {
  Int n, m;
  cin >> n >> m;

  // auto order = compute(n);
  // cout << "TOTAL: " << order.size() << endl;
  // for (int i = 0; i < order.size(); ++i) {
  //   auto p = solve(n, i);
  //   if (p != order[i]) {
  //     output(p);
  //     output(order[i]);
  //     cout << "FAIL: " << i << "\n";
  //   }
  // }

  auto p = solve(n, m - 1);
  for (int x: p) {
    cout << x << " ";
  }
  cout << endl;

  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include<cstdlib>
#include<queue>
#include<cstdio>
#include<map>
#include<iomanip>
#include<cmath>
#include<set>
#include<string>
#define ll long long
#define ld long double
#define pb push_back
#define cs(a) (int)a.size()
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define stol stol_mine
#define se second
#define uch unsigned char
#define MOD 1000000007
#define INF 1000000000
#define EPS (ld)1.2e-15
#define P 29
using namespace std;

vector<int> a;
bool used[100];
int main() {
    int n, mm;
    cin >> n >> mm;
    a.resize(n);
    mm;
    int pos = 0;
    int cur = 1;
    for (int i = 1 << (n - 2); mm > 0; i = max(1, i / 2)) {
        if (mm - i >= 0) {
            mm -= i;
            if (mm == 0) {
                a[pos] = cur;
                used[cur] = true;
                pos++;
            }
            cur++;
        } else {
            a[pos] = cur;
            used[cur] = true;
            pos++;
            cur++;
        }
    }
    cerr << pos << endl;
    cur = n;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 0) {
            for (; used[cur]; cur--);
            a[i] = cur;
            cur = cur - 1;
        }
    }
    for (int i  = 0; i < n; ++i)
        cout << a[i] << " ";
    return 0;
    int mx = 0;
    for (int i = 0; i < n; ++i)
        a[i] = i + 1;
    int m;
    do {
        int s = 0;
        int m = INF;
        for (int i = 0; i < n; ++i) {
            m = INF;
            for (int j = i; j < n; ++j) {
                m = min(m, a[j]);
                s += m;
            }
        }
        mx = max(mx, s);
        if (s == mx) {
            for (int i = 0; i < n; ++i)
                    cout << a[i] << " ";
                cout << endl;
        }
    } while (next_permutation(a.begin(), a.end()));
}

#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:50000000")
typedef long long ll;

using namespace std;

const int maxn = 64;
const int inf = 1e9;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	ll m;
	while (cin >> n >> m) {
		m--;
		vector<int> ans(n);
		int l = 0, r = n - 1;
		for (int i = n - 2; i >= 0; i--) {
			if (m & (1LL << i)) {
				ans[r--] = n - i - 1;
			} else {
				ans[l++] = n - i - 1;
			}
		}
		ans[l] = n;
		for (int i = 0; i < n; i++) cout << ans[i] << " \n"[i + 1 == n];
	}

	return 0;
}

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};

LLI n,m;
void rec(LLI inx,LLI rem)
{
    if(inx==n)
    {
        return;
    }
    LLI rr=n-inx-1;
    LLI p=pow(2ll,rr-1);
//    cout<<"FF : "<<rr<<" "<<p<<"\n";
    if(p<rem)
    {
//                puts("11111");

        rec(inx+1,rem-p);
        cout<<inx+1<<" ";
    }
    else
    {
////        puts("2222");
        cout<<inx+1<<" ";
        rec(inx+1,rem);

    }
//    puts("3333");
}
int main()
{
//    LLI n,m;
    cin>>n>>m;

    rec(0,m);

}

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;

int n,m, u = 1;
int p[55], p2[55];

int provjera() {
    if (u) return 0;
    for ( int i = 1; i < n; i ++ ) {
        if (p[i] < p[i-1]) return 0;
    }
    return 1;
}

int f() {
    int sol = 0;
    for ( int i = 0; i < n; i ++ ) {
        int mn = n + 2;
        for ( int j = i; j < n; j ++ ) {
            mn = min(mn, p[j]);
            sol += mn;
        }
    }
    return sol;
}

int main() {
    scanf("%d %d", &n, &m);
    for ( int i = 1; i <= n; i ++ ) {
        p[i-1] = i;
    }
    int mx = -1;
    while( !provjera() ) {
        u = 0;
        mx = max(mx, f());
        std::next_permutation(p, p + n);
    }
    u = 1;
    int br = 0;
    while( !provjera() ) {
        u = 0;
        int k = f();
        if (k == mx) br ++;
        if (br == m) {
            for ( int i = 0; i < n; i ++ ) {
                printf("%d ", p[i]);
            }
            return 0;
        }
        std::next_permutation(p, p + n);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define max_n 9
int all[9];
vector<vector<int> > sol;
int main(){
//    freopen("in.in","rt",stdin);
    int n,m;cin>>n>>m;
    memset(all,0,sizeof(all));
    for(int i=0;i<=n;i++)all[i]=i;
    int maxx=0;
    do{
        int ex=0,minn=100000;
        for(int i=0;i<n;i++){
            for(int k=i;k<n;k++){
                minn=100000;
            for(int j=i;j<=k;j++)minn=min(minn,all[j]);
            ex+=minn;
            }
        }

        if(ex>maxx){
            maxx=ex;
            sol.clear();
            vector<int > cc;
            for(int i=1;i<=n;i++)cc.push_back(all[i-1]);
            sol.push_back(cc);
        }
        else if(ex==maxx){
            vector<int > cc;
            for(int i=1;i<=n;i++)cc.push_back(all[i-1]);
            sol.push_back(cc);
        }
    }while(next_permutation(all,all+n));
//    cout<<sol.size()<<endl;
    vector<int >cc=sol[m-1];
    for(int i=0;i<n;i++)cout<<cc[i]+1<<" ";

}

#include <cstdio>
#include <cstdlib>
#include <memory.h>
#include <algorithm>

using namespace std;

#define MAXN 16

unsigned a[MAXN], b[MAXN];

int main(void)
  {
  unsigned n, m, q, w, i, t, cur, best;

  scanf("%u %u", &n, &m);

  for(q=0; q<n; ++q)
    a[q] = q+1;

  i=0, best=0;

  do
    {
    for(cur=0,q=0; q<n; ++q)
      for(t=-1U,w=q; w<n; ++w)
        cur += t = min(t, a[w]);

    if(cur>best)
      best=cur, i=0;

    if(cur==best && ++i==m)
      memcpy(b, a, n * sizeof(unsigned));
    } while(next_permutation(a, a+n));

  for(q=0; q<n; ++q)
    printf("%u ", b[q]);

  putchar('\n');

  return 0;
  }

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60;
int ans[MAXN];
long long n, m;
void find(long long cnt, int b, int e, int now) {
    if (b == e)
        return;
    if (cnt <= (long long)1 << (e - b - 2)) {
        ans[b] = now;
        find(cnt, b + 1, e, now + 1);
    }
    else {
        ans[e - 1] = now;
        cnt -= (long long)1 << (e - b - 2);
        find(cnt, b, e - 1, now + 1);
    }

}
int main () {
    cin >> n >> m;
    find(m, 0, n, 1);
    for (int i = 0; i < n; ++i)
        cout << ans[i] << ' ';
    return 0;
}

/* in the name of ALLAH, most gracious, most merciful */
#include<algorithm>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cassert>
#include<utility>
#include<limits>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<stack>
#include<ctime>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define     mems(a,b)       memset(a,b,sizeof(a))
#define     IT              iterator
#define     mp              make_pair
#define     pii             pair<I,I>
#define     fs              first
#define     sc              second
#define     pb              push_back
#define     eps             1E-9
#define     all(a)          a.begin(),a.end()
#define     allr(a)         a.rbegin(),a.rend()
#define     MOD             (1000000007)
#define     llInf           (1LL<<62)
#define     iInf            (2123456789)
#define     min_e           *min_element
#define     max_e           *max_element
#define     lsOne(S)        ((S)&(-(S)))
#define     vhas(c,e)       (find(all(c),e) != c.end())
#define     o(i, start, n)          for(int i = start; i < n; i++)
#define     I3              (ll)1000
#define     I4              (ll)10000
#define     I5              (ll)100000
#define     I6              (ll)1000000
#define     I7              (ll)10000000
#define     I8              (ll)100000000
#define     I9              (ll)1000000000
#define     I10             (ll)10000000000
#define     I11             (ll)100000000000
#define     I12             (ll)1000000000000
#define     I13             (ll)10000000000000
#define     I14             (ll)100000000000000
#define     I15             (ll)1000000000000000
#define     I16             (ll)10000000000000000
#define     I17             (ll)100000000000000000
#define     I18             (ll)1000000000000000000
using namespace std;
typedef long long int ll;
typedef unsigned long long  ull;
typedef double dd;
typedef string str;
typedef char ch;
typedef int I;
inline void _(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
void __(){
    #ifndef ONLINE_JUDGE
    cout << endl << "time elsaped : " << (double)clock() / CLOCKS_PER_SEC << " ms" << endl;
    #endif
}
inline void ___(char *i, char *j){ freopen(i, "r", stdin); freopen(j, "w", stdout); }

//input templates
template<class T1> bool tk(T1 &e1){if(cin>>e1)return true;return false;}
template<class T1,class T2> bool tk(T1 &e1,T2 &e2){if(cin>>e1>>e2)return true;return false;}
template<class T1,class T2,class T3> bool tk(T1 &e1,T2 &e2,T3 &e3){if(cin>>e1>>e2>>e3)return true;return false;}
template<class T1,class T2,class T3,class T4> bool tk(T1 &e1,T2 &e2,T3 &e3,T4 &e4){if(cin>>e1>>e2>>e3>>e4)return true;return false;}
template<class T1,class T2,class T3,class T4,class T5> bool tk(T1 &e1,T2 &e2,T3 &e3,T4 &e4,T5 &e5){if(cin>>e1>>e2>>e3>>e4>>e5)return true;return false;}
template<class T1,class T2,class T3,class T4,class T5, class T6> bool tk(T1 &e1,T2 &e2,T3 &e3,T4 &e4,T5 &e5,T6 &e6){if(cin>>e1>>e2>>e3>>e4>>e5>>e6)return true;return false;}

// output templates
template<class T1> void put(T1 e){cout<<e<<endl;}
template<class T1,class T2> void put(T1 e1,T2 e2){cout<<e1<<" "<<e2<<endl;}
template<class T1,class T2,class T3> void put(T1 e1,T2 e2,T3 e3){cout<<e1<<" "<<e2<<" "<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void put(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void put(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void put(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;}
template<class T1> void putVec(vector<T1>e1){for(I i=0; i<(e1).size(); i++)(!i?cout<<e1[i]:cout<<" "<<e1[i]);cout<<endl;}
template<class T1> void putArr(T1 arr[],I l){for(I i=0; i<l; i++)(!i?cout<<arr[i]:cout<<" "<<arr[i]);cout<<endl;}
// end of output

// bug templates
template<class T1> void bug(T1 e){
    #ifndef ONLINE_JUDGE
    cout<<e<<endl;
    #endif
}
template<class T1,class T2> void bug(T1 e1,T2 e2){
    #ifndef ONLINE_JUDGE
    cout<<e1<<" "<<e2<<endl;
    #endif
}
template<class T1,class T2,class T3> void bug(T1 e1,T2 e2,T3 e3){
    #ifndef ONLINE_JUDGE
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
    #endif
}
template<class T1,class T2,class T3,class T4> void bug(T1 e1,T2 e2,T3 e3,T4 e4){
    #ifndef ONLINE_JUDGE
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
    #endif
}
template<class T1,class T2,class T3,class T4,class T5> void bug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){
    #ifndef ONLINE_JUDGE
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
    #endif
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void bug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){
    #ifndef ONLINE_JUDGE
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
    #endif
}
template<class T1> void bugVec(vector<T1>e1){
    #ifndef ONLINE_JUDGE
    for(I i=0; i<(e1).size(); i++)(!i?cout<<e1[i]:cout<<" "<<e1[i]);cout<<endl;
    #endif
}
template<class T1> void bugArr(T1 arr[],I l){
    #ifndef ONLINE_JUDGE
    for(I i=0; i<l; i++)(!i?cout<<arr[i]:cout<<" "<<arr[i]);cout<<endl;
    #endif
}
// end of bugs

//bit mask operation
template<typename T> inline bool isOn(T &mask,I pos){return ((mask)&(1<<pos));}
template<typename T> inline void setOff(T &mask,I pos){mask = ((mask)&(~(1<<pos)));}
template<typename T> inline void setOn(T &mask,I pos){mask = ((mask)(1<<pos));}
//end of bit mask operations

namespace gv{

};

long long absolute(long long a){
    if(a < 0) return -a;
    return a;
}

int n, mx;
vector<int > a;
vector<vector<int > > v;

void perm(int ind, int mask){
    if(ind == n){
        int this_time = 0;
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                int current = 123456789;
                for(int k = i; k <= j; k++){
                    current = min(current, a[k]);
                }
                this_time += current;
            }
        }
        if(this_time > mx){
            mx = this_time;
            v.clear();
            v.push_back(a);
        }
        else if(this_time == mx){
            v.push_back(a);
        }
        return;
    }
    for(int i = 1; i <= n; i++){
        if(!(mask & (1 << i))){
            a[ind] = i;
            perm(ind + 1, mask | (1 << i));
        }
    }
}

int main()
{_();

    int k;
    tk(n,k); a.clear(); a.resize(n); perm(0,0); sort(all(v)); bug(v.size());
    o(i,0,n){
        cout << v[k - 1][i] << " ";
    }
    put("");

__();}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL dp[55];

int ans[55];

int main(){
	dp[1] = 1;
	for(int i=2;i<=50;i++) dp[i] = dp[i-1]*2;
	int n;
	LL m;
	scanf("%d%lld", &n, &m);

	int s = 1, e = n;
	m--;

	for(int i=1;i<=n;i++){
		int rem = n-i;
		if(m >= dp[rem]) m -= dp[rem], ans[e--] = i;
		else ans[s++] = i;
	}

	for(int i=1;i<=n;i++) printf("%d ", ans[i]);
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 51;
int n, m, pos[N], ans[N];

main() {
    cin >> n >> m;
    int c = 1;
    pos[1] = 1;
    for(int i=2; i<=n; i++) {
        int tmp = pos[i-1];
        if(m < c+(1LL<<(n-i))) {
            for(int j=1; j<=n; j++)
                if(pos[j]>tmp)  pos[j]++;
            pos[i] = tmp+1;
        } else {
            c+=(1LL<<(n-i));
            for(int j=1; j<=n; j++)
               if(pos[j]>=tmp)  pos[j]++;
            pos[i] = tmp;
        }
    }
    for(int i=1; i<=n; i++)
        ans[pos[i]] = i;
    for(int i=1; i<=n; i++)
        cout << ans[i] << " ";
}

#include <cstdio>

int main() {
    for(long long n, m; ~scanf("%lld%lld", &n, &m);) {
        int a[n], l = 0, r = n-1;
        long long p = 1; p <<= n-2;

        for(int i = 1; i <= n; i++, p>>=1)
            if(m > p) a[r--] = i, m -= p;
            else      a[l++] = i;

        for(int i = 0; i < n; i++)
            printf("%d%c", a[i], i==n-1?'\n':' ');
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 10000000
#define f first
#define pi pair<ll,ll>
#define pb push_back
#define mod 1000000007
#define s second
#define fr freopen("s1.txt","r",stdin)
#define fo freopen("s2.txt","w",stdout)
ll encode(vector<ll>&v){
    ll ans=0;
    ll cur=1;
    for(auto x:v){
        ans=ans+cur*x;
        cur*=10;
    }
    return ans;
}
int main(){
vector<ll>v;
ll n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) v.pb(i);
vector<ll>vt;
ll sum=0;
ll rt=0;
//ll mini[10];
do{
    rt=0;
    ll mini=INF;
    for(int i=0;i<n;i++){
        mini=INF;
        for(int j=i;j<n;j++){
            mini=min(mini,v[j]);
            rt+=mini;
        }
    }
    if(sum==rt) vt.pb(encode(v));
    else if(sum<rt){
        sum=rt;
        vt.clear();
        vt.pb(encode(v));
    }
}while(next_permutation(v.begin(),v.end()));
sort(vt.begin(),vt.end());
ll h=vt[m-1];
vector<ll>ans;
while(h>0){
    ans.pb(h%10);
    h/=10;
}
reverse(ans.begin(),ans.end());
for(auto x:ans) cout<<x<<" ";
}

#include <bits/stdc++.h>
using namespace std;
int n, a[10], m;

int Va(int a[]) {
    int res = 0;
    for (int i = 1; i <= n; i++) {
        int mi = a[i];
        for (int j = i; j <= n; j++) {
            mi = min(mi, a[j]);
            res += mi;
        }
    }
    return res;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) a[i] = i;
    int mx = 0;
    do {
        mx = max(mx, Va(a));
    } while (next_permutation(a + 1, a + n + 1));
    for (int i = 1; i <= n; i++) a[i] = i;
    do {
        if (Va(a) == mx) m--;
        if (m == 0) {
            for (int i = 1; i <= n; i++) cout << a[i] << " ";
            return 0;
        }
    } while (next_permutation(a + 1, a + n + 1));
}

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vi perm(n);
    for (int i = 0; i < n; ++i) perm[i] = i+1;
    int cur = 0, mx = 0;
    vi ans;
    do {
        int aux = 0;
        for (int i = 0; i < n; ++i) {
            int mn = perm[i];
            for (int j = i; j < n; ++j) {
                mn = min(mn, perm[j]);
                aux += mn;
            }
        }
        if (aux > mx) {
            cur = 1;
            mx = aux;
            if (cur == m) ans = perm;
        } else if (aux == mx) {
            cur++;
            if (cur == m) ans = perm;
        }
    } while (next_permutation(perm.begin(), perm.end()));
    for (int i = 0; i < n; ++i) cout << ans[i] << " ";
    cout << "\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
#define GCD(a,b) __gcd(a, b)
#define mp make_pair
#define DEBUG(x) cout << x << "\n"
#define ALL(x) x.begin(), x.end()
#define INF (1 << 30)
#define pb push_back

ll n, m, nums[777];
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    int l = 0, r = n - 1;
    for (int j = n - 1; j > 0; --j) {
        ll half_point = (1LL << (j - 1));
        if (m <= half_point) {
            nums[l++] = n - j;
        }
        else {
            nums[r--] = n - j;
            m -= half_point;
        }
    }
    nums[l] = n;
    for (int i = 0; i < n; ++i) {
        if (i > 0) cout << " ";
        cout << nums[i];
    }

}

/* 문제
    2015.

*/

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>

#define ENP     printf("**Entry Point**\n")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef vector  <double>            vec_d;
typedef vector  <vec_d>             vvec_d;
typedef vector  <int>               vec_i;
typedef vector  <vec_i>             vvec_i;
typedef pair    <int, int>          pair_i;
typedef pair    < pair_i, pair_i >  pp_i;

const int INF = 0x7fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 100001;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int n;
    ll m;
    scanf("%d%I64d", &n,&m);

    m--;
    ll now = 1LL << (n - 2);

    int ans[51] = { 0 };
    int pos[2] = { 0, n - 1 };
    int cnt = 1;
    bool judge;

    if (m >= now)
        judge = true;
    else
        judge = false;

    for (int i = 0; i < n; i++)
    {
        if (m >= now)
        {
            ans[pos[1]] = cnt;
            m -= now;
            pos[1]--;

            judge = true;
        }
        else
        {
            ans[pos[0]] = cnt;

            pos[0]++;
            judge = false;
        }
        cnt++;
        now >>= 1;
    }

    for (int i = 0; i < n; i++)
    {
        printf("%d ", ans[i]);
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,m,a[10],ans[10];
int main()
{
    cin>>n>>m;
    for (int i=1;i<=n;i++)
        a[i]=i;
    int minn=0,cnt=0;
    do
    {
        int tmp=0;
        for (int i=1;i<=n;i++)
        {
            int tmpp=11111;
            for (int j=i;j<=n;j++)
            {
                tmpp=min(tmpp,a[j]);
                tmp+=tmpp;
            }
        }
        if (tmp>minn) minn=tmp,cnt=0;
        if (tmp==minn)
        {
            cnt++;
            if (cnt==m)
                for (int i=1;i<=n;i++)
                    ans[i]=a[i];
        }
    }
    while(next_permutation(a+1,a+n+1));
    for (int i=1;i<=n;i++)
        cout<<ans[i]<<' ';
}

#include <cstdio>

int main(){
	int n;
	long long m;
	scanf("%d%I64d",&n,&m);
	long long bitmask = (1LL<<(n-1))- m;
	for(int i=n-2;i>=0;--i){
		if(bitmask&(1LL<<i))printf("%d ",n-i-1);
	}
	printf("%d",n);
	for(int i=0;i<n-1;++i){
		if(!(bitmask&(1LL<<i)))printf(" %d",n-i-1);
	}
	printf("\n");
	return 0;
}

#include<cstdio>
long long n,m,i,u[64];
int main(){
 scanf("%d%I64d",&n,&m);m--;
 for(i=n;--i;)if(!(m&(1LL<<i-1)))printf("%d ",n-i),u[n-i]=1;
 for(;n;n--)if(!u[n])printf("%d ",n);
}

#include <bits/stdc++.h>
#define MAX 50
#define llu long long unsigned
using namespace std;

llu perm[MAX];

void f(llu m,llu n,llu a,llu b,llu k){
    if(a==b){
        perm[a] = k;
        return;
    }
    llu d = (1LL<<(n-2));
    if(m <= d){
        perm[a] = k;
        f(m,n-1,a+1,b,k+1);
    }else{
        perm[b] = k;
        f(m-d,n-1,a,b-1,k+1);
    }

}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    llu n,m;
    cin >> n >> m;

    f(m,n,0,n-1,1);

    for(auto i=0;i<n;i++){
        cout << perm[i] << " ";
    }

    cout<<endl;

    return 0;
}

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-9;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f;
const LL inf=(((LL)1)<<61)+5;
int n;
LL m;
vector<int> dfs(int n,LL m)
{
    vector<int> V;
    if(n==2)
    {
        if(m==1) V.pb(1),V.pb(2);
        else V.pb(2),V.pb(1);
        return V;
    }

    LL p=1;
    if(m<=(p<<(n-2)))
    {
        V=dfs(n-1,m);
        vector<int> ans;
        ans.pb(1);
        for(int i=0;i<V.size();i++) ans.pb(V[i]+1);
        return ans;
    }
    V=dfs(n-1,(p<<(n-1))+1-m);
    reverse(V.begin(),V.end());
    for(int i=0;i<V.size();i++) V[i]++;
    V.pb(1);
    return V;
}

int main()
{
    cin>>n>>m;
    if(n==1)
    {
        puts("1");
        return 0;
    }
    vector<int> V=dfs(n,m);
    for(int i=1;i<=n;i++)
    {
        if(i>1) putchar(' ');
        printf("%d",V[i-1]);
    }
    puts("");
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

#include <cstdio>

using namespace std;

int n; long long m;

long long p[60];

vector<int> easy() {
  vector<int> a(n);
  iota(a.begin(), a.end(), 1);

  int sm = 0;

  do {
    int s = 0;
    for (int i = 0; i < n; ++i) {
      int m = a[i];
      for (int j = i; j < n; ++j) {
        m = min(m, a[j]);

        s += m;
      }
    }
    if (sm < s) {
      sm = s;
    }
  } while(next_permutation(a.begin(), a.end()));

  int cnt = 0;

  do {
    int s = 0;
    for (int i = 0; i < n; ++i) {
      int m = a[i];
      for (int j = i; j < n; ++j) {
        m = min(m, a[j]);
        s += m;
      }
    }
    if (sm == s) {
      ++cnt;
    }
    if (cnt == m) {
      return a;
    }
  } while(next_permutation(a.begin(), a.end()));
//  cout <<"cnt " << cnt << '\n';
  return a;
}

vector<int> hard() {
  p[0] = 1;
  for (int i = 1; i < 60; ++i) p[i] = p[i - 1] * 2;
  vector<int> a(n);
  long long x = m - 1;
  int c1 = 0, c2 = n - 1;

  for (int i = 1; i <= n; ++i) if (x >= p[n - i - 1]) {
    a[c2--] = i;
    x -= p[n - i - 1];
  }else a[c1++] = i;
  return a;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("data.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m;

//  n = 5;
//  for (m = 1; m < 20; ++m) {
//    for (int i: easy()) cout << i << ' '; cout << '\n';

//  }
//  return 0;

//  vector<int> a = easy();
//  vector<int> b = hard();
//  for (int i = 0; i < n; ++i) if (a[i] != b[i]) {
//    cout << n << ' ' << m << '\n';
//    for (int i: a) cout << i << ' '; cout << '\n';
//    for (int i: b) cout << i << ' '; cout << '\n';
//    return 0;
//  }

  for (int i: hard()) cout << i << ' '; cout << '\n';

}

#include<iostream>
#include<vector>
using namespace std;

int main() {
	long long int n,m;
	cin>>n>>m;
	vector<int>v;
	while(n!=0) {
		v.push_back(0);
		n--;
	}
	int x=0;
	vector<int> vx;

	while(x<v.size()-1||(v.size()==1&&x==0)) {
		vx.push_back(0);
		x++;
	}
	x=0;
	m-=1;
	while(m!=0) {
		if(m%2!=0) {
			m=(m-1)/2;
			vx[x]=1;
		}
		else {
			m/=2;
			vx[x]=0;
		}
		x++;
	}

	n=1;
	int s=vx.size()-1;
	int left=0,right=v.size()-1;

	while(left<=right) {
		if(vx[s]==0) {
			v[left]=n;
			left++;
		}
		else {
			v[right]=n;
			right--;
		}
		n++;
		s--;
	}

	n=0;
	while(n!=v.size()) {
		cout<<v[n]<<" ";
		n++;
	}

	return 0;
}

// Problem : B1. Permutations
// Contest : Rockethon 2015
// URL : https://codeforces.com/problemset/problem/513/B1
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;
const int N = 1e6;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v;
    vector<vi> ans;
    for (int i = 0; i < n; ++i) {
        v.push_back(i + 1);
    }
    int mx = 0;
    do {
        int sm = 0;
        for (int i = 0; i < n; ++i) {
            int mn = INT_MAX;
            for (int j = i; j < n; ++j) {
                mn = min(mn, v[j]);
                sm += mn;
            }
        }
        if (sm >= mx) {
            if (sm == mx)
                ans.push_back(v);
            else {
                ans.clear();
                ans.push_back(v);
                mx = sm;
            }
        }
    } while (next_permutation(all(v)));
    for (int k = 0; k < n; ++k) {
        cout << ans[m - 1][k] << " ";
    }
}

#include "stdio.h"
#include <string>
#include <vector>
#include <algorithm>

#define FOR(i, n) for(i = 0; i < n; i++)
#define SFOR(i, m, n) for(i = m; i < n; i++)
#define FORD(i, n) for(i = (int)n - 1; i>=0; i--)

using namespace std;

int main() {
	long long m, n, i, j, k;
	scanf("%I64d%I64d", &n, &m);
	//vector<int> A;
	//FOR(i, n) A.push_back(i+1);
	//int M = 0;
	//do {
	//	int s = 0;
	//	FOR(i, n) {
	//		SFOR(j, i+1, n+1) {
	//			int s1 = 1000;
	//			SFOR(k, i, j) s1 = min(s1, A[k]);
	//			s += s1;
	//		}
	//	}
	//	M = max(M, s);
	//} while (next_permutation(A.begin(), A.end()));
	//int m1 = m;
	//do {
	//	int s = 0;
	//	FOR(i, n) {
	//		SFOR(j, i + 1, n+1) {
	//			int s1 = 1000;
	//			SFOR(k, i, j) s1 = min(s1, A[k]);
	//			s += s1;
	//		}
	//	}
	//	if (s == M) {
	//		m--;
	//		if (m == 0) {
	//			FOR(i, n) printf("%d ", A[i]);
	//			printf("\n");
	//			break;
	//		}
	//	}
	//} while (next_permutation(A.begin(), A.end()));
	//m = m1;
	long long C[51][51];
	FOR(i, 51) { C[0][i] = 0; C[i][0] = 0; }
	FOR(i, 50) FOR(j, 50) C[i + 1][j + 1] = C[i][j] + C[i][j - 1];
	long long P[51];
	P[0] = 1;
	FOR(i, 50) P[i + 1] = P[i] * 2;
	int K = 1;
	vector<int> Q, W;
	m -= 1;
	while (m != 0) {
		j = 1;
		while (m > 0 && m >= P[n - j - 1]) {
			m -= P[n - j - 1];
			j++;
		}
		n -= j;
		Q.push_back(K + j - 1);
		j--;
		FOR(i, j) W.push_back(K + i);
		K += j + 1;
	}
	FOR(i, n) Q.push_back(K + i);
	FOR(i, Q.size()) printf("%d ", Q[i]);
	FORD(i, W.size()) printf("%d ", W[i]);
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

void print(vector<int>& v)
{
  for(int i = 0 ; i < sz(v) ; i++)
    cout << v[i] << " ";
  cout << endl;
}

int f(vector<int>& p, int s, int e)
{
  if(s > e) return 0;
  int m = s;
  for(int i = s ; i <= e ; i++){
    if(p[m] > p[i])
      m = i;
  }
  return f(p, s, m - 1) + p[m] * (m - s + 1) * (e - m + 1) + f(p, m + 1, e);
}

void solve(int n)
{
  int best = 0;
  vector<int> p;
  vector<vector<int>> sol;
  for(int i = 0 ; i < n ; i++)
    p.pb(i + 1);
  do{
    int cur = f(p, 0, n - 1);
    if(cur > best){
      sol.clear();
      sol.pb(p);
      best = cur;
    }else if(cur == best){
      sol.pb(p);
    }
  }while(next_permutation(all(p)));
  cout << n << " " << best << endl;
  for(int i = 0 ; i < sz(sol) ; i++)
    print(sol[i]);
  cout << "-------\n";
}

int ans[55];

void solve(int cur, int s, int e, long long comp, long long mth)
{
  if(s == e){
    ans[s] = cur;
    return;
  }
  if(mth <= comp){
    ans[s] = cur;
    solve(cur + 1, s + 1, e, comp >> 1, mth);
  }else{
    ans[e] = cur;
    solve(cur + 1, s, e - 1, comp >> 1, mth - comp);
  }
}

int main()
{
  int n;
  long long m;
  cin >> n >> m;
  solve(1, 0, n - 1, (1LL << (n - 2)), m);
  for(int i = 0 ; i < n ; i++)
    cout << ans[i] << " ";
  cout << endl;
  return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
    int n;
    unsigned long long m;
    cin >> n >> m;
    m=m-1;
    int a[n-1];
    for(int i=n-2;i>=0;i--){
        a[i]=m%2;
        m/=2;
    }
    for(int i=0;i<n-1;i++)
        if(a[i]==0) cout << i+1 << " ";
    cout << n << " ";
    for(int i=n-2;i>=0;i--)
        if(a[i]==1) cout << i+1 << " ";
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi a;
	repn(i, 1, n + 1) a.pb(i);
	vector<vi> nums;
	int best = 0;
	do{
		int sum = 0;
		rep(i, n) repn(j, i, n){
			int mn = 1e9;
			repn(k, i, j + 1) mn = min(mn, a[k]);
			sum += mn;
		}
		if(sum > best){
			nums.clear();
			best = sum;
		}
		if(sum == best) nums.pb(a);
	} while(next_permutation(all(a)));
	sort(all(nums));
	rep(i, nums[m - 1].size()) cout << nums[m - 1][i] << " ";
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/

// Roman V. Konovalov
// Microsoft Visual Studio Express 2013 for Windows Desktop

#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

template <class T>
class zArray{
	friend class TestzArray;
protected:
	int n;
	T *p;
	void CriticalError(){
		//Application->MessageBox("Range Out","zArray Critical Error");
		cout << "zArray Critical Error: Range Out";
	}
	virtual int RealLen(int i){
		//return 10*((i-1)/10+1);  -> Old release
		if (i == 0)return 0;
		int RL = 1;
		i--;
		for (; i>0; i >>= 1)RL <<= 1;
		return RL;
	}
public:
	zArray(){
		n = 0;
	}
	~zArray(){
		Free();
	}
	int Len(){
		return n;
	}
	void Free(){
		if (n)delete[]p;
		n = 0;
	}
	void SetLen(int new_n){
		if (new_n<0)return;
		if (RealLen(n) == RealLen(new_n) && n != 0 && new_n != 0){
			n = new_n;
			return;
		}
		T *new_p = 0;
		int min = (n<new_n ? n : new_n);
		if (new_n)new_p = new T[RealLen(new_n)];
		for (int i = 0; i<min; i++)new_p[i] = p[i];
		if (n)delete[]p;
		n = new_n;
		p = new_p;
	}

	T & operator [](int i){
		if (i< -n || i >= n){//CriticalError();
			string s = "Range Out:  Array Size = ";  //s += to_string(n);
			s += "  Call operator [] with value = "; //s += to_string(i);
			//Application->MessageBox(s.c_str(),"zArray Critical Error");
			cout << "zArray Critical Error: " << s;
		}
		if (i >= 0)return p[i];
		else    return p[n - (-i)];
	}
	T & last(){
		if (n == 0)CriticalError();
		return p[n - 1];
	}
	T* GetP(){
		if (!n)return 0;
		return p;
	}

	T& Add(){
		SetLen(n + 1);
		return last();
	}
	void Add(T &t){
		SetLen(n + 1);
		p[n - 1] = t;
	}

	void Delete(int i){
		if (i<0 || i >= n)CriticalError();
		for (int k = i; k<n - 1; k++)p[k] = p[k + 1];
		SetLen(n - 1);
	}
	T& Insert(int i){
		if (i<0 || i>n)CriticalError();
		Add();
		for (int k = n - 1; k>i; k--)p[k] = p[k - 1];
		return p[i];
	}
	void Insert(int i, T &t){
		Insert(i) = t;
	}
	zArray & operator=(const zArray &a){
		if (this == &a)return *this;
		SetLen(a.n);
		for (int i = 0; i<n; i++)p[i] = a.p[i];
		return *this;
	}

	void Sort(){
		T *tmp = new T[n];
		T *m, *m1 = p, *m2 = tmp;
		int i1, i2, j, keylen;

		for (keylen = 1; keylen<2 * n; keylen *= 2){   // exampl: n=5
			for (j = 0; j<n; j += 2 * keylen){
				for (i1 = i2 = 0; i1<keylen && i2<keylen && j + keylen + i2<n;){
					if (m1[j + i1] <= m1[j + keylen + i2]){
						m2[j + i1 + i2] = m1[j + i1];        i1++;
					}
					else{
						m2[j + i1 + i2] = m1[j + keylen + i2]; i2++;
					}
				}
				for (; i1<keylen && j + i1<n; i1++)
					m2[j + i1 + i2] = m1[j + i1];
				for (; i2<keylen && j + keylen + i2<n; i2++)
					m2[j + i1 + i2] = m1[j + keylen + i2];
			}
			m = m1;
			m1 = m2;
			m2 = m;
		}
		delete[]tmp;
	}
	bool CheckSort(){
		int i;
		for (i = 1; i<n; i++)if (p[i - 1]>p[i]){
			//Application->MessageBox("Sort Algorithm Incorrectly",
			//                        "MemArray Critical Error");
			cout << "zArray Critical Error: MemArray Critical Error";
			return false;
		}
		return true;
	}

	int BinSearch(T &value){
		// 1. ���� �������� � ����� ��������� ���,
		// ���������� �����-������ ������� � ����� ������
		// (������� ��� ������� value).
		// 2. ���� ��������� ��������� �� ��������� value,
		// �� ���������� ������� � ���������� �������.
		// 3. Method use only "bool operator <=(const T&)"
		// definition for type T
		if (n == 0)return -1;
		int i, min = 0, max = n - 1;
		while (true){
			if (min == max)return min;
			if (min + 1 == max){
				if (value <= p[min])return min;
				return max;
			}
			i = min + (max - min) / 2;
			if (value <= p[i])max = i;
			else           min = i;
		}
	}
};

typedef zArray <int> zIntArray;
typedef zArray <double> zDoubleArray;
typedef zArray <string> zStringArray;
typedef zArray <char> zCharArray;
typedef zArray <zIntArray> zInt2DArray;
typedef zArray <zDoubleArray> zDouble2DArray;
typedef zArray <zStringArray> zString2DArray;
typedef zArray <zCharArray> zChar2DArray;

//###################################################################

int Get10(int n, int i){
	int k,nn=n;
	for (k = 0; nn>0; k++)nn /= 10;
	for (; k!=i; k--)n /= 10;
	return n % 10;
}

void main(){
	cout.precision(15);
	int n, m;
	string s, ns;
	cin >> n >> m;
	m--;

	s = '0' + n;
	for (n--; n > 0; n--){
		ns = '0' + n;
		if ((m % 2) == 0)s = ns + " " + s;
		else s = s + " " + ns;
		m >>= 1;
	}

	cout << s;
}

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main () {

 int n;
 long long m;
 cin >> n >> m;

 long long amt = 1;
 for (int i = 1; i < n; ++i) {
  amt *= 2;
 }

 vector<int> answer(n);
 int left = 0, right = n - 1;
 int number = 1;
 while (number < n) {
  amt /= 2;
  if (amt < m) {
   answer[right] = number;
   --right;
   m -= amt;
  } else {
   answer[left] = number;
   ++left;
  }
  ++number;
 }
 answer[left] = number;
 for (int i = 0; i < n; ++i) {
  cout << answer[i] << " ";
 }
 return 0;
}

#define FNAME ""

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>

#define pb push_back
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define vi vector<int>
#define vvi vector<vi>
#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define fornr(i, n) for (int i = n - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = a; i < (int) b; i++)
#define gcd __gcd

#ifdef WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

template <class T> T sqr(const T &a) {return a * a;}

int n, ans[60], used[60];
LL fact[60], m;

int main()
{
//	freopen(FNAME".in", "r", stdin);
//	freopen(FNAME".out", "w", stdout);

	scanf("%d" I64, &n, &m);
	fact[0] = 1;
	forab(i, 1, 51)
		fact[i] = fact[i - 1] * i;

	int l = 0, r = n - 1;
	forn(i, n)
	{
		if (n - i - 2 < 0 || 1ll<<(n - i - 2) < m)
			m -= 1ll<<(n - i - 2), ans[r--] = i + 1;
		else
			ans[l++] = i + 1;
	}
	forn(i, n)
		printf("%d ", ans[i]);
	puts("");
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll n,m;
ll a[1005];

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>m;
    ll l=0,r=n-1;
    for(int i=n-1;i>0;i--)
    {
        if(m<=pow(2,i-1))
        {
            a[l++]=n-i;
        }
        else
        {
            a[r--]=n-i;
            m-=pow(2,i-1);
        }
        //m/=2;
    }
    a[l]=n;
    for(int i=0;i<n;i++)cout<<a[i]<<" ";
    return 0;
}

//compile c++11 with -std=c++0x in g++
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
#define getchar_unlocked getchar
#define pb push_back
#define mp make_pair
#define f first
#define sc second
#define pii pair<int,int>
#define M 1000000007
#define inf (int)(2e+9)
#define all(o) (o).begin(), (o).end()
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
LL max(LL a,LL b,LL c){return max(a,max(b,c));}
inline LL power(LL x,LL y)
{
    LL ans=1;
    while(y>0){
        if(y&1)
            ans=(ans*x)%M;
        x=(x*x)%M;
        y/=2;
    }
    return ans;
}
inline int read()
{
	int ret = 0,temp=1;
	int c = getchar_unlocked();
	while(c<'0' || c>'9'){
		c = getchar_unlocked();
	}
	while(c>='0' && c<='9')
	{
		ret = (ret<<3) + (ret<<1) + c - '0';
		c = getchar_unlocked();
	}
        return ret;
}
LL mulmod(LL a,LL b) {
   long double res = a;
   res *= b;
   LL c = (LL)(res / M);
   a *= b;
   a -= c * M;
   a %= M;
   if (a < 0) a += M;
   return a;
}
int n;
int a[55];
void solve(int pos,LL m,int l,int r)
{
  if(pos==n) return;
  LL k=1LL<<(n-pos-2);
  if(m<=k){
    a[l]=pos+1;
    solve(pos+1,m,l+1,r);
  }
  else
  {
    a[r]=pos+1;
    solve(pos+1,m-k,l,r-1);
  }
}
int main()
{
    LL m;
    scanf("%d %I64d",&n,&m);
    solve(0,m,0,n-1);
    for(int i=0;i<n;i++) printf("%d ",a[i]);
      printf("\n");
}

#include<bits/stdc++.h>

using namespace std;

vector<vector<int> > vec;
int n;
int formule(vector<int> tab){
	int mi, sum = 0;
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			mi = INT_MAX;
			for(int k=i;k<=j;k++){
				mi = min(mi,tab[k]);
			}
			sum+=mi;
		}
	}
	return sum;
}
void cpy(int tab1[], int tab2[]){
	for(int i=0;i<n;i++)
		tab2[i] = tab1[i];
}

int permut(vector<int> tab){
	int ma = INT_MIN;
	vec.push_back(tab);
	ma = max(ma,formule(tab));
	while(next_permutation(tab.begin(), tab.end())){
		vec.push_back(tab);
		ma = max(ma,formule(tab));
	}
	return ma;
}

int main(){
	int m;
	cin>>n>>m;
	vector<int> tab;
	int cnt = 0;
	for(int i=0;i<n;i++)
		tab.push_back(i+1);
	//cout<<"formule test  = "<< formule(tab)<<endl;
	int ma = permut(tab);
	//cout<<"size = "<<vec.size()<<endl;
	//cout<<"ma = "<<ma<<endl;
	for(auto & el : vec){
		int k = formule(el);
		//cout<<"max = "<<k<<endl;
		if(k==ma)
			cnt++;
		if(cnt==m){
			for(auto & in : el)
				cout<<in<<" ";
			break;
		}
	}

}

    #include <iostream>
    #include <vector>
    using namespace std;

    int n, m;
    bool b[10];
    vector<int> h;
    int maxs = 0;
    vector<vector<int> > v;
    vector<int> vm;
    void dfs(int x) {
    if(x >= n) {
    int s = 0;
    for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
    int mm = h[i];
    for(int k = i; k <= j; k++)
    if(h[k] < mm) mm = h[k];
    s += mm;
    }
    }
    if(s > maxs)
    maxs = s, v.clear();
    if( s == maxs)
    v.push_back(h);
    return;
    }
    for(int i = 1; i <= n; i++ ) {
    if(!b[i]) {
    b[i] = true;
    h.push_back(i);
    dfs(x + 1);
    h.pop_back();
    b[i] = false;
    }

    }
    }

    int main() {
    cin >> n >> m;
    dfs(0);
    for(int i = 0; i < n; i++)
    cout << (i == 0 ? "" : " ") << v[m - 1][i];
    cout << endl;
    return 0;
    }

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false);
    int n; //n [1, 50]
    ll m; //m [1, cntn] cntn = 2^(n - 1) (n bits))
    cin >> n >> m;
    vector<int> p(n + 1, 0);
    int offset = 0; //offset of substring indices, offset + n is n's position
    //O(n)
    for(int i = 1; i < n; i++){
        //[2^(n - i - 1) + 1, 2^(n - i)]
        //
        //n - i - 1 >= 0, i!=n because negative shift is undefined!
        //although the answer is correct ,
        //offset + n and offset + i are the same when i == n
        //if the code will not be destroyed.
        ll small = (1LL << (n - i - 1));
        if(m <= small){
            //keep i's position, overwrite the moved one if offset < 0
            p[offset + i] = i;
        }else{
            //move i to the end
            p[offset + n] = i;
            //move [i + 1, n] left
            //offset + n will not be updated later
            //current position is reserved (offset --, i++)
            offset --;
            //2^(n - i - 1) + c, go to find the No.c permutations of
            //substring [i + 1, n]
            m -= small;
        }
    }
    p[offset + n] = n;
    for(int i = 1; i <= n; i++){
        if(i != 1){
            cout << ' ';
        }
        cout << p[i];
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m;
	cin >> n >> m;
	long long int dp[n+100];
	dp[0] = 1;
	for(int i = 1;i <= n;i++)
		dp[i] = dp[i-1]*2;
	long long int a[n];
	long long int l = 1;
	long long int r = n;
	for(long long int i = 1;i <= n;i++){
		if(m > dp[r-l-1]){
			m -= dp[r-l-1];
			a[r] = i;
			r--;
		}
		else{
			a[l] = i;
			l++;
		}
	}
	for(int i = 1;i <= n;i++)
		cout << a[i] << " ";
}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define tf(x) get<0>(x)
#define ts(x) get<1>(x)
#define tt(x) get<2>(x)
#define endl '\n'
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define tup tuple<int,int,int>
#define ve vector <int>
#define vep vector<pii >
#define mod 1000000007
#define maxn 2e5+5
#define ld long double
#define in insert
#define fr(i,a,b) for(int i=a;i<b;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define fora(m) for(auto it:m)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef
tree<
  int,
  null_type,
  less<int>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;

int mull(int  a,int b)  {
    return ((a%mod)*(b%mod))%mod;
}

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

//--------------------------------SIEVE---------------------------//
/*bool prime[maxn];
int spf[maxn];
void sieve() {
	forn(i,maxn) {
		prime[i]=true;
		spf[i]=i;
	}
	fr(i,2,maxn) {
		if(prime[i]){
			for(int j=2*i;j<maxn;j+=i) {
				prime[j]=false;
				spf[j]=i;
			}
		}
	}
}*/

//-----------------------------End---------------------------------//

//------------------------------------------------DFS------------------------//
/*bool stat[maxn];
int depth[maxn],par[maxn];
void init_graph() {
	memset(stat,false,sizeof(stat);
	memset(depth,0,sizeof(depth);
	for(int i=0;i<maxn;i++) par[i]=i;
}
void dfs(int u,int p) {
	stat[u]=true;
	depth[u]=depth[p]+1;
	par[u]=p;
	for(auto it:g[u]) {
		if(stat[it]==false)
			dfs(it,u);
	}
}*/

//-------------------------------------DFS-END--------------------------------//

//-----------------------------------nCr%p-----------------------------------//
/*int nCr(int n, int r)
{
   if (r==0)
      return 1;
    int fac[n+1];
    fac[0] = 1;
    for (int i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%mod;

    return (fac[n]* modInverse(fac[r], mod) % mod *
            modInverse(fac[n-r], mod) % mod) % mod;
} */
//---------------------------------EnD---------------------------------------//

void solve() {
	int n,m;
	cin>>n>>m;
	int a[n]={0},l=0,r=n-1,curr=1;
	n=n-1;
	while(l<=r) {
		int tmp=power(2,n-1,1e18);
		//cout<<tmp<<endl;
		if(tmp>=m) {
			a[l]=curr;
			l++;
			curr+=1;
		}
		else {
			a[r]=curr;
			r--;
			curr+=1;
			m=m-tmp;
		}
		n=n-1;
	}
//	cout<<a[1];
	fora(a) {
		cout<<it<<" ";}
}
signed main() {
	IOS
	int t=1;
	//cin>>t;
	while(t--) {
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define maxn int(2e6 + 12)
#define maxb int(2e6 + 12)
#define inf int(1e9 + 7)
#define linf ll(1e18 + 12)
#define eps 1e-7
#define mp make_pair
#define pb push_back
#define fn "b"
#define f first
#define s second

template<typename T>
T min(T a, T b, T c)
{
 return min(a, min(b, c));
}

template<typename T>
T max(T a, T b, T c)
{
 return max(a, max(b, c));
}

vector <int> v;
multimap <ll, vector <int>> s;
int n, m;

ll get()
{
 ll ans = 0ll;
 for (int l = 0; l < n; l++)
  for (int r = l; r < n; r++)
  {
   ll now = v[l];
   for (int k = l; k <= r; k++)
    now = min(now, ll(v[k]));
   ans += now;
  }
 return ans;
}

int main()
{
 cin>>n>>m;
 for (int i = 1; i <= n; i++)
  v.pb(i);
 ll maxx = -inf;
 do
 {
  ll ans = get();
  maxx = max(maxx, ans);
  s.insert(mp(ans, v));
 } while(next_permutation(v.begin(), v.end()));

 auto it = s.lower_bound(maxx);
 int t = 1;
 for (; it != end(s) && t < m; it++, t++);
 v = it -> s;
 for (int i = 0; i < n; i++)
  cout<<v[i]<<' ';
  }

#include <algorithm>
#include <iostream>
#include <set>

using namespace std;

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n;
    long long m;
    cin >> n >> m;
//    m--;
    int k = n - 2;
    set<int> s;
    for (int i = 1; i <= n; ++i) {
        s.insert(i);
    }
    int last = 0;
    for (int i = 1; i <= n; ++i) {
        set<int>::iterator z = s.upper_bound(last);
        if (z == s.end()) {
            while (!s.empty()) {
                cout << *s.rbegin() << ' ';
                s.erase(*s.rbegin());
            }
            break;
        }
        for (int j = k; j >= 0; --j) {
            if (m > 1LL << j) {
                m -= 1LL << j;
                ++z;
                --k;
            } else break;
        }
        --k;
        cout << *z << ' ';
        last = *z;
        s.erase(z);
    }
}

#include <iostream>
#include <utility>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>

int main( int argc, char** argv)
{
	int n;
	long long m;
	std::cin >> n >> m;
	int *p = new int[n];
	int l = 0, r = n-1;
	for (int i = n - 1; i > 0; --i)
	{
		if (m <= (1LL << (i - 1)))
		{
      p[l++] = n - i;
    }else{
      p[r--] = n - i;
      m -= (1LL << (i - 1));
    }
  }
	p[l] = n;
	for( int i = 0; i<n; ++i)
		std::cout << p[i] << " ";
	std::cout << std::endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int n,m,p[8];

int f(int p[]){
	int ac=0;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++){
			int m=9;
			for(int k=i-1;k<j;k++) m=min(m,p[k]);
			ac+=m;
		}
	return ac;
}

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++) p[i]=i;
	int M=0;
	do{
		M=max(M,f(p));
	}while(next_permutation(p,p+n));
	sort(p,p+n);
	do{
		if(f(p)==M) m--;
		if(m==0){
			for(int i=0;i<n;i++) cout<<p[i]+1<<' ';
			return 0;
		}
	}while(next_permutation(p, p+n));
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n, k;
ll pw[60];
int ans[60];
int f = 0, e;

void make(int sz, ll tmp, deque<int> &val);

int main() {
	cin >> n >> k;
	e = n - 1;
	pw[0] = 1;
	pw[1] = 1;
	for (int i = 2; i <= n; i++) {
		pw[i] = pw[i - 1] + pw[i - 2];
	}

	deque<int> val;
	for (int i = 0; i < n; i++)
		val.push_back(i + 1);
	make(n, k, val);

	for (int i = 0; i < n; i++)
		cout << ans[i] << " ";

	cout << endl;

	return 0;
}

void make(int sz, ll tmp, deque<int> &val) {
	if (sz == 0)
		return;
	if (val.size() == 1) {
		ans[f++] = val[0];
		return;
	}
	if (tmp <= pw[sz - 2]) {
		ans[f++] = val[0];
		val.pop_front();
		make(sz - 1, tmp, val);
		return;
	}
	int f1 = val.front();
	val.pop_front();
	ans[f++] = val[0];
	ans[e--] = f1;
	val.pop_front();
	tmp -= pw[sz - 2];
	make(sz - 2, tmp, val);
}

#include <iostream>
#include <math.h>
#include <string.h>
#include <cstring>
#include <vector>
#include <algorithm>
#define ft first
#define se second
#define Max 10001000
#define st(s) s.size();
#define r(input) freopen("input.txt","r",stdin)
#define w(output) freopen("output.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define un(v) Sort(v), v.erase(unique(v.begin(),v.end()),v.end())
#define cover(a,d) memset(a,d,sizeof(a))
using namespace std;
long long int arr[1000000];
long long int arrs[1000000];
vector <long long> p;
int main()
{
    int n1,n2,s=0,counter=0,sum=0;
    cin >> n1 >> n2;

    for(int i=0;i<n1;i++){
        arr[i]=i+1;
        arrs[i]=i+1;
    }
    for(int i=0;i<n2;i++){
        for(int j=i;j<n1;j++){
            sum+=arr[j];
        }
        if(sum>s){
            s=sum;
            counter=i;
        }
        next_permutation(arr,arr+n1);
    }
    for(int i=0;i<counter;i++)next_permutation(arrs,arrs+n1);
    for(int i=0;i<n1;i++)cout << arrs[i] << " " ;
    cout << "\n";
    return 0;
}

#include <iostream>
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <list>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <stack>
#include <functional>
#include <math.h>
#include <queue>
#include <vector>
#include <bitset>
#include <cstdio>
#pragma comment(linker, "/STACK:2560000000000")
#pragma warning(disable : 4996)
typedef long long ll;
typedef long double lb;
#define MP make_pair
#define eps 1e-4
#define INF 1111111111

using namespace std;

int main () {
	ll n, m;
	cin >> n >> m;
	vector <int> p;
	for (int i = 1; i <= n; i++)
		p.push_back(i);

	for (int i = 1; i < m; i++)
		next_permutation(p.begin(), p.end());

	for (int i = 1; i <= n; i++)
		cout << p[i - 1] << ' ';
}

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

bool alldone(vector<bool> done)
{
	for(int i=0;i<done.size();++i)
	{
		if(!done[i]) return false;
	}
	return true;
}

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<bool> done(n,false);
	vector<int> ans (n);
	ll tofind = m;
	int digval,base;
	ll totans;
	int rem;
	int st=0;
	int end = n-1;
	while(!alldone(done))
	{
		for(int i=0;i<n;++i)
		{
			if(!done[i]){
				 base = digval = i+1;
				 rem = n-i-1;
				 break;
			}
		}
		totans = 1<<rem;
		while(totans < 2*tofind && totans>1)
		{
			digval++;
			totans>>=1;
			tofind-=totans;
		}
		ans[st++] = digval;
		done[digval-1] = true;
		for(;base < digval ;++base)
		{
			done[base-1] = true;
			ans[end--] = base;
		}
	}
	for(int i=0;i<n;++i)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    m--;
    vector<bool>v;
    while(m>0)
    {
        v.push_back(m%2);
        m/=2;
    }
    cout<<v.size()<<endl;
    for(int i=0;i<n-1;i++)
    {
        if((i+1<(n-v.size()))|| (v[(n-(i+1))-1]==0))
        {
          //  if(i+1>=(n-v.size()))
          //  cout<<"ok";
         cout<<i+1<<" ";

        }
    }
    cout<<n<<" ";
    for(int i=0;i<v.size();i++)
    {
        if(v[i])
        cout<<(n-i)-1<<" ";
    }
}

//written by mhadih
#include <iostream>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <string>

using namespace std;

//#define cin inf
//#define cout of

typedef long long ll;

const ll N = 2e5;
const ll INF = 1e15;
const ll MOD = 1000000007;

ll n,m,a[100],t[100];

void slove(ll l,ll r,ll x)
{
	if (l==r) { a[l] = n; return; }
	ll j = n-(r-l);
	if (m<=t[r-l-1])
	{
		a[l] = j;
		slove(l+1,r,m);
	}
	else
	{
		a[r] = j;
		slove(l,r-1,m-t[r-l-1]);
	}
}

int main()
{
    ios::sync_with_stdio(false);
    ifstream inf("input.txt");
	t[0] = 1;
	for (int i = 1; i<=60; i++)
		t[i] = t[i-1]*2;
	cin >> n >> m;
	slove(1,n,m);
	for (int i = 1; i<=n; i++)
		cout << a[i] << ' ';
}

#pragma comment(linker, "/STACK:128777216")

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>

#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>

#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>

#include <memory.h>
#include <cassert>
#include <time.h>

using namespace std;

#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;

const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;

#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  }
#define dbg( ... ) {  }
#endif

void prepare(string s)
{
#ifdef MY_DEBUG
    freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
#else
    if (s.length() != 0)
    {
        freopen ((s + ".in").c_str(), "r", stdin);
        freopen ((s + ".out").c_str(), "w", stdout);
    }
#endif
}

const int NMAX = 55;

int n, k;
int p[NMAX];

void read()
{
    scanf("%d %d", &n, &k);
}

int f()
{
    int r = 0;
    for(int i = 0; i < n; i++)
    {
        int t = p[i];
        for(int j = i; j < n; j++)
        {
            t = min(t, p[j]);
            r += t;
        }
    }
    return r;
}

void go(vector<int> &t, int k)
{
    sort(all(t));
    if (k == 1)
        return;

    int s = sz(t);
    int k2 = 1LL << (s - 1);
    if (k2 >= k)
    {
        vector<int> t2;
        forab(i, 1, sz(t) - 1)
            t2.pb ( t[i] );
        go( t2, k );
        forn(i, sz(t2))
            t[i + 1] = t2[i];
    }
    else
    {
        k2 = (1LL << s) - k2;
        go(t, k2);
        reverse(all(t));
    }
}

void solve()
{
    vector<int> a;
    forn(i, n)
        a.pb ( i + 1 );
    go( a, k );
    forn(i, sz(a))
        printf("%d ", a[i]);

    return;

    forn(i, n)
        p[i] = i + 1;
    int t = -INF;
    do
    {
        t = max(t, f());
    } while(next_permutation(p, p + n));

    forn(i, n)
        p[i] = i + 1;

    int c = 0;
    do
    {
        if (t == f())
            c ++;
        if (t == f())
        {
            forn(i, n)
                printf("%d ", p[i]);
            printf("\n");
        }
    }while(next_permutation(p, p + n));
}

int main()
{
    prepare("");

    read();
    solve();

    return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int arr[57];

int main()
{
	int n, m, a , b;
	cin >> n >> m;
	a = 0;
	b = n-1;
	int num = pow(2, n-2);
	for (int i = 0; i < n; i++)
	{
		if(m <= num)
		{
			arr[a] = i+1;
			a++;
			num /= 2;
		}
		else
		{
			arr[b] = i+1;
			b--;
			m-=num;
			num/=2;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout << arr[i] << " ";
	}
};

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _ ios::sync_with_stdio(false);
#define mem(x,a) memset(x,(a),(int)(sizeof(x)))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define bitcount __builtin_popcount
#define ison(a,b) (a&(1<<b))
#define nl cout<<endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si size()
#define V vector
ll mod=1e9+7;
int main() {
	int n,m;
	cin>>n>>m;
	vector<int> v(n);
	fr(i,0,n-1)v[i]=i+1;
	m--;
	while(m)
	{
		//for(auto i:v)cout<<i<<" ";nl;
		next_permutation(v.begin(),v.end());
	m--;
	}
	for(auto i:v)cout<<i<<" ";nl;

	return 0;
}

#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10];
int b[10],c[10];
int main()
{
     int i,j;
     int n,m;
     scanf("%d%d",&n,&m);
     for(i=1;i<=n;i++)
     {
          a[i]=i;
          b[i]=i;
     }
     for(i=2;i<=m;i++)
          next_permutation(b+1,b+1+n);
     int max=0;
     do
     {
          int sum=0;
          int tx;
          for(i=1;i<=n;i++)
          {
               tx=a[i];
               for(j=i;j<=n;j++)
               {
                    tx=min(a[b[i]],a[b[j]]);
                    sum+=tx;
               }
          }
          if(sum>max)
          {
               max=sum;
               for(i=1;i<=n;i++)
                    c[i]=b[i];
          }
     }
     while(next_permutation(a+1,a+1+n));
     for(i=1;i<=n-1;i++)
          printf("%d ",c[i]);
     printf("%d\n",c[i]);
     return 0;
}

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include <queue>
#include<string>
#include<cstring>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
//11094 accepted 2d array BFS :) :)
#define MOD 1000000007
#define MX 100010
int NODES;

#define pii pair<int,int>
int row,col;
int check(int tx,int ty)
{
	if(tx>=0 && tx<row && ty>=0 && ty<col)
		return 1;
	return 0;
}

int main()
{
	int test_cases=0,i,j,n,x=0,k,m,y=0;
	char G[105][105];

	int S,T,u,v,w,ret;

	char str;
	int n1,n2,k1,k2;
	while(scanf("%d%d",&n,&m) == 2)
	{
		vector<int>B;
		map< vector<int>, int>mymap;
		for(i=1;i<=n;i++)
			B.push_back(i);
		i=0;
		int max=0;
		do{
			int res = 0,sum=0;
			for(i=0;i<n;i++)
			{
				for(j=0;j<n;j++)
				{
					x = n;
					for(k=i;k<=j;k++)
					{
						x =std::min(x,B[k]);
					}
					res = res+x;
				}
				sum =sum+res;
			}
			if(max<=sum)
			{
			mymap[B]++;
			max = sum;
			}
		} while (next_permutation(B.begin(),B.end()));
		map< vector<int>, int>::iterator it=mymap.begin();
		for(it=it,i=1 ;it!=mymap.end();it++,i++)
		{
			if(i==m)
			{
				B.clear();
				B = it->first;
				for(i=0;i<B.size()-1;i++)
					cout<<B[i]<<" ";
				cout<<B[i]<<"\n";
				break;
			}
		}

	}
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include<map>
#define pi acos(-1.0)
#define eps 1e-6
#define inf 1<<30
#define INF 1ll<<60
#define ll long long
using namespace std;

int main()
{
    int a[60];
    for(int i=0;i<55;i++)
        a[i]=i+1;
    int n,m;
    cin>>n>>m;
    m--;
    while(m--)
    {
        next_permutation(a,a+n);
    }
    for(int i=0;i<n;i++)
    {
        if(!i)
            cout<<a[i];
        else
            cout<<" "<<a[i];
    }
    cout<<endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <cstdint>
#include <vector>
#include <map>
using namespace std;

int n, m;
int ans, cnt;

vector<bool> was;
vector<int> x;
vector<int> v;

void rec(int q = 0)
{
	if (q == n)
	{
		int sum = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = i; j < n; ++j)
			{
				int mx = 1e9;
				for (int k = i; k <= j; ++k)
					mx = min(mx, v[k]);
				sum += mx;
			}
		}

		++cnt;
		if (cnt >= m && sum > ans)
		{
			ans = sum;
			x = v;
		}
		return ;
	}

	for (int i = 1; i <= n; ++i)
	{
		if (!was[i])
		{
			v.push_back(i);
			was[i] = true;
			rec(q + 1);
			v.pop_back();
			was[i] = false;
		}
	}
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	was.resize(50);
	rec();
	for (int i = 0; i<n; i++)
	{
		cout << x[i] << " ";
	}
	return 0;
}

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <math.h>

int Max = 0;
int n, m, y = 1;
int a=1;
int dv=1;

std::vector<int> M;

int FindMin(int first, int last){

    int min = M[first];

    for (int i = first + 1; i <= last; i++){
        if (min>M[i]) min = M[i];
    }

    return min;
}

int FindMax(){

    int Sum = 0;
    int Min1;

    for (int i = 0; i<n; i++){
        for (int j = i; j<n; j++){
            Min1 = FindMin(i, j);
            Sum = Sum + Min1;
        }
    }

    return Sum;
}

int main(){

    int k = 0, g;

    scanf("%d %d", &n, &m);

    std::vector<int> Final;

    for (int i = 0; i<n; i++) M.push_back(i + 1);

    do{
        g = FindMax();
        if (Max<g){
            Max = g;
            y = 0;
        }
        if (Max == g) {
            y++;
            if (y == m) Final = M;
        }
    } while (std::next_permutation(M.begin(), M.end()));

    do{
        g = FindMax();
        if (Max == g) {
            for (int i = 0; i<n; i++){
                printf("%d ", M[i]);
            }
            printf("\n");
        }
    } while (std::next_permutation(M.begin(), M.end()));

    for (int i = 1; i <= n - 2; i++){
        dv = dv * 2;
    }

    int b = dv;
    int b2 = dv;
    int dv2 = dv*2;
    int* F = new int[n];
    int i = 0,m2=m;

    while ((a<=n)&&(m2!=0)){
        while ((m2 > b)&&(b != 0)){
            m2 = m2 - b;
            b = b / 2;
            a++;
            printf("m2 %d b %d a %d\n",m2,b,a);

        }
        F[i] = a;
        i++;
        dv = dv / 4;
        b = dv;
        a++;
        printf("F %d dv %d a %d\n", F[i-1], dv, a);
    }

//

    k = n;
    a = 1;
    int m3 =dv2-m+1;

    while ((a < n) && (k != i)){
        while ((m3 > b2) && (b2 != 0)){
            m3 = m3 - b2;
            b2 = b2 / 2;
            a++;
        }
        k--;
        F[k] = a;
        dv2 = dv2 / 4;
        b2 = dv2;
        a++;
    }

    printf("\n");

    for (int i = 0; i<n; i++){
        printf("%d", F[i]);
    }
//
    printf("\n");
    for (int i = 0; i<n; i++){
        printf("%d", Final[i]);
    }
    delete[] F;

    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#define debug puts("-----")
#define pi (acos(-1.0))
#define eps (1e-8)
#define inf (1<<4)
#define ll long long int
using namespace std;

#define MAXN 8+10

int n, m;
int a[MAXN];
int Max = 0;

int main(int argc, char const *argv[])
{
    memset(a, 0, sizeof(a));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        a[i] = i ;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j++)
        {
            Max += i;
        }
    }
    if (m != 1)
    {
        do
        {
            int tmp = 0;
            for (int i = 1; i <= n; i++)
            {
                for (int j = i; j <= n; j++)
                {
                    int Min = inf;
                    for (int k = i; k <= j; k++)
                    {
                        Min = min(a[k], Min);
                    }
                    tmp += Min;
                }
            }
            if (tmp == Max)    m--;
        }
        while (next_permutation(a + 1, a + n + 1) && m - 1);
    }
    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << ' ';
    }
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
// #include<string>
#include<vector>
// #include<map>
#include<algorithm>
// #include<cmath>
using namespace std;
int m,n;
int a[20];
struct node{
	int index;
	int x;
	node(int a=0,int b=0):index(a),x(b){}
	bool operator < (const node& a) const{
		if(x>a.x) return x>a.x;
		return index>a.index;
	}
};

int main()
{
	cin >> n >> m;
	vector<node> v;
	for(int i=0;i<n;++i) a[i]=i+1;
	int cnt=0;
	do{
//		cout << "cnt="<<cnt<<"===";
//			for(int i=0;i<n;++i) cout << a[i] <<" ";
		int sum=0;
		for(int i=0;i<n;++i){
			for(int j=i;j<n;++j){
				int minn=a[i];
				for(int k=i+1;k<=j;++k)
					if(minn>a[k]) minn=a[k];
				sum+=minn;
			}
		}
		v.push_back(node(cnt,sum));
//		cout << "sum=" <<sum <<endl;
		cnt++;
	}while(next_permutation(a,a+n));

	sort(v.begin(),v.end());
	// for(int i=0;i<v.size();++i) printf("%d-%d ",v[i].index,v[i].x);
	// printf("\n");
	int index=v[m-1].index;
//cout << "index="<<index<< endl;
	for(int i=0;i<n;++i) a[i]=i+1;
	do{
		if(index==0){
			for(int i=0;i<n-1;++i) printf("%d ",a[i]);
			cout << a[n-1] <<endl;
			break;
		}
		index--;
	}while(next_permutation(a,a+n));

	return 0;
}

#include <bits/stdc++.h>
#define AND &&
#define x1 fjewioafkjwaoi
#define y1 kfewpaofkaewpof
#define int long long
using namespace std;

const int nmax = 300010;

int n, m;

main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);

    cin >> n >> m;
    vector<int> a, b;
    for (int i=1; i<n; i++){
        int left = (1 << (n-i-1));
        if (m<=left) {

            a.push_back(i);
        } else m-=left, b.push_back(i);
    }
    for (int i=0; i<a.size(); i++) cout << a[i] << " ";
    cout << n << " ";
    reverse(b.begin(), b.end());
    for (int i=0; i<b.size(); i++) cout << b[i] << " ";

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include<map>
#define pi acos(-1.0)
#define eps 1e-6
#define inf 1<<30
#define INF 1ll<<60
#define ll long long
using namespace std;
int main()
{
    int n,m;
    int a[111];
    cin>>n>>m;
    int l=0;
    int r=n-1;
    for(int i=0;i<n;i++)
    {
        if(m>=(1ll<<n-1-i))
        {
            a[r--]=i+1;
        }
        else
        {
            a[l++]=i+1;
            m-=1ll<<n-1-i;
        }
    }
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define ff first
#define ss second
const  int mod = 1e9 + 7;
const int inf = 1e18;
using namespace std;

main()
{
    int n, m; cin>>n>>m;
    int per[n+1];

    for(int i = n-m+1, j = n; i <= n; i++, j--)
        per[i] = j;

    f(i, 1, n-m+1)
        per[i] = i;

    f(i, 1, n+1)
        cout<<per[i]<<" ";
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <assert.h>

using namespace std;

int n;
long long m;

int main() {
	cin >> n >> m;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	if (n == 2) {
		if (m == 1) {
			cout << 1 << ' ' << 2 << endl;
		} else {
			cout << 2 << ' ' << 1 << endl;
		}
		return 0;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int k = 1;
		vector<pair<int, int> > v;
		v.push_back(make_pair(1, i));
		v.push_back(make_pair(i + 2, n));
		long long d[100];
		memset(d, 0, sizeof(d));
		while (k < n) {
			int t = 200;
			for (int j = 0; j < (int)v.size(); j++) {
				if (v[j].second >= v[j].first   && v[j].second >= v[j].first && v[j].first >= 1) {
					t = min(t, v[j].second - v[j].first);
				}
			}
			for (int j = 0; j < (int)v.size(); j++) {
				if (v[j].second -= v[j].first == t   && v[j].second >= v[j].first && v[j].first >= 1) {
					d[k + 1]++;
					if (t % 2 != 0) {
						d[k + 1]++;
					}
				}
			}
			int l = (int)v.size();
			for (int j = 0; j < l; j++) {
				if (v[j].second -= v[j].first == t  && v[j].second >= v[j].first && v[j].first >= 1) {
					v.push_back(make_pair((v[j].second + v[j].first) / 2 + 1, v[j].second));
					v[j].second = (v[j].second + v[j].first) / 2 - 1;
					break;
				}
			}
			//cout << "opa" << endl;
			k++;
		}
		d[1] = 1;
		//cout << d[1] << endl;
		for (int j = n; j >= 1; j--) {
			if (j == n) {
				d[j] = 1;
			} else {
				d[j] = d[j + 1] * d[j];
				if (d[j] >= 10000000000000000LL) {
					for (int j1 = j - 1; j1 >= 1; j1--) {
						d[j1] = d[j];
					}
					break;
				}
			}
		}
		//cout << d[3] << endl;
		k = 1;
		v.clear();
		v.push_back(make_pair(1, i));
		v.push_back(make_pair(i + 2, n));
		//cout << "k" << endl;
		//cout << d[1] << endl;
		if (d[1] < m) {
			ans += d[1];
			continue;
		}
		int a[100];
		a[i] = 1;
		while (k < n) {
			int t = 200;
			for (int j = 0; j < (int)v.size(); j++) {
				if (v[j].second >= v[j].first  && v[j].second >= v[j].first && v[j].first >= 1) {
					t = min(t, v[j].second - v[j].first);
				}
			}
			long long s = 0;
			for (int j = 0; j < (int)v.size(); j++) {
				if (v[j].second -= v[j].first == t && v[j].second >= v[j].first && v[j].first >= 1) {
					s++;
					if (t % 2 != 0) {
						s++;
					}
				}
			}
		//	cout << s << endl;
			long long s1 = 0;
			for (int j = 0; j < (int)v.size(); j++) {
				if (v[j].second -= v[j].first == t  && v[j].second >= v[j].first && v[j].first >= 1) {
					s1++;
					//cout << "opa" << endl;
					//cout << (d[k] / s)  << endl;
					//cout << d[k] << endl;
					if ((d[k] / s) * s1 + ans >= m) {
					//	cout << "opa" << endl;
					//	cout << (d[k] / s) * s1 + ans << endl;
					//	cout << v[j].second << ' ' << v[j].first << endl;
						// for (int g = 0; g < (int)v.size(); g++) {
						// 	cout << v[g].first << ' ' << v[g].second << endl;
						// }
						// cout << endl;
						//cout << (v[j].second + v[j].first) / 2 << endl;
						a[(v[j].second + v[j].first) / 2 - 1] = k + 1;
						v.push_back(make_pair((v[j].second + v[j].first) / 2 + 1, v[j].second));
						v[j].second = (v[j].second + v[j].first) / 2 - 1;
						ans += (d[k] / s) * (s1 - 1);
						//cout << "opa "<< endl;
						break;
					}
					if (t % 2 != 0) {
						s1++;
					}
					//cout << (d[k] / s) * s1 + ans << endl;
					if ((d[k] / s) * s1 + ans >= m) {
					//	cout << "opa" << endl;
					//	cout << (d[k] / s) * s1 + ans << endl;
					//	cout << v[j].second << ' ' << v[j].first << endl;
						// for (int g = 0; g < (int)v.size(); g++) {
						// 	cout << v[g].first << ' ' << v[g].second << endl;
						// }
						//cout << endl;
						//cout << (v[j].second + v[j].first) / 2 << endl;
						a[(v[j].second + v[j].first + 1) / 2 - 1] = k + 1;
						v.push_back(make_pair((v[j].second + v[j].first + 1) / 2 + 1, v[j].second));
						v[j].second = (v[j].second + v[j].first + 1) / 2 - 1;
						ans += (d[k] / s) * (s1 - 1);
						//cout << "opa "<< endl;
						break;
					}
				}
			}
			k++;
			sort(v.begin(), v.end());
			//cout << (int)v.size() << endl;
		}
		for (int j = 0; j < n; j++) {
			cout << a[j] << ' ';
		}
		cout << endl;
		return 0;
	}
  	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<bool> isThere;
string t;
vector<string> p;
vector<int> sums;

void tryit(int i,int n);
int sum(int x,int n);

int main() {
    int n,m;
    cin>>n>>m;

    for (int i=0; i<=n; ++i)
        isThere.push_back(false);

    tryit(1, n);

    sort(p.begin(), p.end());

    int max=0;
    sums.resize(n);
    for (int i=0; i<p.size(); ++i) {
        sums[i]=sum(i, n);
        if (sums[i]>max)
            max=sums[i];
    }

    int x=0;
    while (m!=0) {
        if (sums[x]==max)
            --m;
        ++x;
    }

    --x;
    for (int i=0; i<p[x].size(); ++i) {
        cout<<(int)p[x][i]<<" ";
    }
    cout<<endl;

    return 0;
}

void tryit(int i,int n) {
    for (int j=1; j<=n; ++j) {
        if (!isThere[j]) {
            t.push_back(j);
            isThere[j]=true;
            if (t.size()==n) {
                p.push_back(t);
            }
            else
                tryit(j,n);
            t.pop_back();
            isThere[j]=false;
        }
    }
}

int sum(int x,int n) {
    int s=0;

    vector<int> t;
    for (int i=0; i<p[x].length(); ++i)
        t.push_back(int(p[x][i]));

    for (int i=0; i<n; ++i) {
        for (int j=i; j<n; ++j) {
            int min=300000;
            for (int k=i; k<=j; ++k)
                if (t[k]<min)
                    min=t[k];
            s+=min;
        }
    }

    return s;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<climits>
#include<cstring>

using namespace std;

typedef long long LL;

bool check(string s)
{
    int i=2;
    while( (s[i]-s[i-1])* (s[i-1]-s[i-2])>0)
    {
        i++;
    }

    i++;
    for(;i<s.length(); i++)
    {
        if( (s[i]-s[i-1]) * (s[i-1]-s[i-2]) <0)
            return false;
    }
    return true;
}

int main()
{
     ios_base::sync_with_stdio(false);

     int n, m;
     cin>>n>>m;
     vector <string> ret;

     string s;
     for(char c='1'; c<=n+'0'; c++)
      s+=c;

      do
      {
          if(check(s))
            ret.push_back(s);

      }while(next_permutation(s.begin(), s.end()));

      string x=ret[m-1];
      for(int i=0; i<x.length(); i++)
        cout<<x[i]<<' ';
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pp;
typedef unsigned long long ull;
#define FOR(i, n) for(int i = 0; i < int(n); i++)
#define FORAB(i, a, b) for(int i = int(a); i <= int(b); i++)
#define FORTR(it, container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define what_is(x) cerr<< #x <<" = "<<x<<endl;
#define inp(x) cin>>x
#define outi(x) cout<<x
#define out(x) cout<<x<<endl
#define popcount(x) __builtin_popcount(x)
#define gcd(x,y) __gcd(x,y)
const int inf = 1e9;
const long long MAXINT_64 = numeric_limits<ll>::max();
const long long MININT_64 = numeric_limits<ll>::min();
const long double PI = ld(3.1415926535897932384626433832795);

void calc(int n){
	int arr[51];
	FOR(i,n){
		arr[i] = i+1;
	}
	int totalsummax = 0;
	int index = 0;
	do{
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		totalsummax = max(totalsum, totalsummax);
	}while(next_permutation(arr, arr+n));
	int z = 0;
	do{
		index++;
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		if(totalsum==totalsummax){
			FOR(i,n) cout<<arr[i]<<" "; cout<<" = "<<totalsum<<" "<<index<<endl;
		}
	}while(next_permutation(arr, arr+n));
	cout<<"z = "<<z<<endl;
}
void calc1(int n, int m){
	int arr[51];
	FOR(i,n){
		arr[i] = i+1;
	}
	int totalsummax = 0;
	int index = 0;
	do{
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		totalsummax = max(totalsum, totalsummax);
	}while(next_permutation(arr, arr+n));
	int z = 0;
	do{
		int totalsum = 0;
		FOR(i,n){
			int minval = arr[i];
			int sum = 0;
			for(int j=i;j<n;j++){
				minval = min(minval, arr[j]);
				sum += minval;
			}
			totalsum += sum;
		}
		if(totalsum==totalsummax){
			index++;
			if(index == m){
				FOR(i,n) cout<<arr[i]<<" "; cout<<" = "<<totalsum<<" "<<index<<endl;
				return;
			}
		}
	}while(next_permutation(arr, arr+n));
	cout<<"z = "<<z<<endl;
}

vector<int> solve(int n, int m){
	if(n == 1){
		vector<int> answer = {1};
		return answer;
	}
	if(n == 2){
		if(m==1){
			vector<int> answer = {1,2};
			return answer;
		}
		else{
			vector<int> answer = {2,1};
			return answer;
		}
	}
	int mid = pow(2,n-2);
	vector<int> answer;
	if(m <= mid){
		answer = solve(n-1,m);
		FOR(i,answer.size())
			answer[i] += 1;
		answer.insert(answer.begin(), 1);
	}
	else{
		answer = solve(n-1,m-mid);
		FOR(i,answer.size())
			answer[i] += 1;
		answer.pb(1);
	}
	return answer;
}

int main(){
    ios::sync_with_stdio(false);
    int n,m;
//    calc(2);
//    calc(3);
//    calc(4);
//    calc(5);
//    calc(7);
    inp(n); inp(m);
//    calc(n,m);
    vector<int> answer = solve(n,m);
    FOR(i,answer.size())
    	cout<<answer[i]<<" ";
    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;

void dfs(int c, int m, int p, int l, int r, int *a) {
    if(l > r) return;
    if(m > p) a[r--] = c, m -= p;
    else      a[l++] = c;
    dfs(c+1, m, p>>1, l, r, a);
}
int main() {
    for(int n, m; ~scanf("%d%d", &n, &m);) {
        int a[n];
        dfs(1, m, 1<<(n-2), 0, n-1, a);
        printf("%d", a[0]);
        for(int i = 1; i < n; i++)
            printf(" %d", a[i]);
        printf("\n");
    }
}

/*
 * File:   cf513B2.cpp
 * Author: Bslin
 * Mail:   Baoshenglin1994@gmail.com
 *
 * Created on Sun 08 Feb 2015 10:59:27 AM CST
 */

#include <cstdio>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
#endif
    int n, m, i;
    int ans[60];
    while(~scanf("%d%d", &n, &m)) {
        int l = 0, r = n - 1;
        for (i = n - 1; i > 0; i --) {
            if(m <= 1LL << (i - 1)) {
                ans[l ++] = n - i;
            } else {
                ans[r --] = n - i;
            }
        }
        ans[l ++] = n - i;
        for (i = 0; i < n; ++i) {
            printf("%d ", ans[i]);
        }
        puts("");
    }
    return 0;
}

//in the name of allah
//ya ali

#include<iostream>

#include<fstream>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define ll  (long long int)
#define forn(i,n) for(int i=1;i<=n;i++)
using namespace std;
int y;

int main()
{long long int a,d,i;
	cin>>a;
	cin>>d;
	int q[a+1];

	long long int m=0;
	vector<int> v;
	string s;
	int f=d;
	int n[a];
	int u=0;
for(int j=0;j<a;j++)
n[j]=0;
	int t=0;
	while(f>0)
	{v.push_back(f%2);

	n[a-1-t]=f%2;
		f=f/2;
	t++;
	}
int g=0;
for(int i=0;i<a;i++)
	{
		if(n[i]==1)
		{
			q[a-1-g]=i+1;
			g++;
		}

	}
	g=0;
	for(int i=0;i<a;i++)
	{
		if(n[i]==0)
		{q[g]=i+1;
		g++;

		}
	}
	for(int h=0;h<a;h++)
	cout<<q[h]<<" ";

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <string.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#define mod 1e9+7
#define MAX 200005
using namespace std;
int main()
{
    int n,m,i,j,a[60]={0},t;
    scanf("%d%d",&n,&m);
    for(i=j=1;i<=(n+1)/2;i++,j+=2) a[i]=j;
    for(i=n,j=2;i>(n+1)/2;i--,j+=2) a[i]=j;
    if(n==3)
    {
        if(m==1) printf("1 2 3\n");
        else if(m==2) printf("1 3 2\n");
        else if(m==3) printf("2 3 1\n");
        else if(m==4) printf("3 2 1\n");
        return 0;
    }
    for(m--,j=n/2;j>0&&m>0;j--)
    {
        if(m&1)
        {
            t=a[j];
            a[j]=a[n+1-j];
            a[n+1-j]=t;
        }
    }
    printf("%d",a[1]);
    for(i=2;i<=n;i++) printf(" %d",a[i]);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	long long m;
	vector <bool> per;
	vector <int> res;
	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		res.push_back(i);
	}
	m--;
	while(m){
		next_permutation(res.begin(),res.end());
		m--;
	}
	cout << res[0];
	for(int i = 1; i < (int)res.size(); i++){
		cout << " " << res[i];
	}
	cout << endl;
}

#include<bits/stdc++.h>
#define pb push_back
#define INF 100
#define N 55
#define int long long
using namespace std;
int n,m,i,a[N],b[N];
void go(int l,int r,int m)
{
    int k,f,i,j;
    if (m==1) return;
    k=1<<(r-l-1);
    j=l;
    while (true)
    {
        if (m<=k) break;
        if (m>k) m-=k;
        k/=2;
        if (k==0) k=1;
        f/=2;
        j++;
    }
    //cout<<l<<" "<<r<<" "<<m<<" "<<j<<endl;
    for (i=1;i<=n;++i)
     b[i]=a[i];
    for (i=j;i<=r;++i)
     b[l+i-j]=a[i];
    for (i=j-1;i>=l;--i)
     b[l+(r-j)+j-i]=a[i];
    for (i=1;i<=n;++i)
     a[i]=b[i];
    go(l+1,r-j+1,m);
}
main()
{
    //cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    if (m==1)
    {
        for (i=1;i<=n;++i)
         cout<<i<<" ";
        return 0;
    }
    if (m==(1<<(n-1)))
    {
        for (i=n;i>0;--i)
         cout<<i<<" ";
        return 0;
    }
    for (i=1;i<=n;++i)
     a[i]=i;
    go(1,n,m);
    for (i=1;i<=n;++i)
     cout<<a[i]<<" ";
}

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<math.h>
using namespace std;
#define N 41000
#define ll long long
const int inf=0x1f1f1f1f;
int f[N][8];
int a[10];
struct node
{
    int index,sum;
}b[N];
int work(int *a,int n)
{
    int i,j,k,t,sum=0;
    for(i=1;i<=n;i++)
    {
        for(j=i;j<n;j++)
        {
            for(k=i,t=0;k<j;k++)
                t=min(t,a[k]);
            sum+=t;
        }
    }
    return sum;
}
bool cmp(node a,node b)
{
    return a.sum>b.sum;
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,m,cnt;
    while(scanf("%d%d",&n,&m)!=-1)
    {
        for(i=1;i<=n;i++)
            a[i]=i;
        for(i=1;i<=n;i++)
            f[0][i]=a[i];
        b[0].sum=work(a,n);
        b[0].index=0;
        j=1;
        while(next_permutation(a+1,a+n+1))
        {
            b[j].sum=work(a,n);
            b[j].index=j;
            for(i=1;i<=n;i++)
            {
                f[j][i]=a[i];
            }
            j++;
        }
        sort(b,b+j,cmp);
        for(i=1;i<n;i++)
            printf("%d ",f[b[m-1].index][i]);
        printf("%d\n",f[b[m-1].index][n]);

    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define LL long long
#define MP make_pair
#define pii pair <int , int>
#define L first
#define R second
//203148Ck

LL A[60];

int main()
{
 LL n,m , cnt = 1 , Le = 0 , Ri = 0;
 cin >> n >> m;
 Ri = n - 1;
 m--;

 for(LL i = n - 2 ;i >= 0; i-- , cnt++){
    if((1 << i) & m)
        A[Ri] = cnt , Ri--;
    else
        A[Le] = cnt , Le++;
 }
 A[Le] = n;
 for(LL i = 0 ;i < n ; i++)
    cout << A[i] <<" " ;
 return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;
bool check(vi &a, int k){
    int ans = 0;
    REP(i, a.size()){
        int x = INF;
        for(int j = 0; j+i < a.size(); j++){
            x = min(x, a[j+i]);
            ans += x;
        }
    }
    if(ans != k) return false;
    REP(i, a.size()){
        cout << a[i] << ":";
    }
    cout << " -> " << ans << endl;

    if(ans == k) return true;
    return false;
}

int main(void){
    int n, m;
    cin >> n >> m;
    vector<ll> tp(55, 1LL);
    m--;

    if(!m){
        REP(i, n){
            if(!i) cout << i+1;
            else cout << " " << i + 1;
        }
        cout << endl;
        return 0;
    }

    for(int i = 3; i < 55; i++) tp[i] = tp[i-1] * 2;
    //for(int i = 1; i < 55; i++) tp[i] += tp[i-1];
    vi a(n);
    REP(i, n) a[i] = i + 1;
	vi use(n+1, 0);
    use[0] = 1;
    int cnt = n;
    vi ans;
    while(m){
        ll id = 1;
        ll s = 0LL;
        for(int i = 0; ; i++){
            id = tp[cnt-i];
            s += id;
            //cout << "id" << id << " s : " << s << endl;
            if(s > m){
                m -= s - id;
                id = i;
                break;
            }
        }

        //cout << m << ": << id " << id << endl;
        int k = 1;
        while(use[k]) k++;
        while(1){
            //cout << "k and id " << k << ":" << id << endl;
            if(id == 0) break;
            if(!use[k]) id--;
            k++;
        }
        use[k] = 1;
        ans.push_back(k);
        cnt--;
    }
    RREP(i, use.size()){
       if(!use[i]) ans.push_back(i);
    }
    REP(i, n){
        if(!i) cout << ans[i];
        else cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef complex<double> C;

void print(const vector<int>& p) {
    for (int el : p) {
        cout << el << " ";
    }
    cout << endl;
}

bool done[55];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll m;
    cin >> n >> m;
    vector<int> p(n);
    int l = 0, r = n-1;
    m--;
    if (m == 0) {
        cout << 1 << endl;
        return 0;
    }
    int cur = 0;
    while (r-l > 0) {
        int i = 0;
        for (i = cur; i < n; i++) {
            if ((m>>(n-2-i)) & 1) m -= 1ll<<(n-2-i);
            else break;
        }
        cur = i+1;
        p[l++] = i+1;
        done[i] = true;
        for (int j = 0; j < i; j++) {
            if (!done[j]) {
                p[r--] = j+1;
                done[j] = true;
            }
        }
    }
    print(p);
    return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

vector <int> solve(long long n, long long m)
{
	if (n == 1) {
		return vector <int> (1,1);
	}
	long long cur = 1LU << (n - 2);
	vector <int> res;
	if (m >= cur) {
		res = solve(n - 1, m - cur);
		res.push_back(0);
		for (int i = 0; i < res.size(); i++)
			res[i]++;
	} else {
		res = vector <int> (1, 1);
		vector <int> a = solve(n - 1, m);
		for (int i = 0; i < a.size(); i++)
			res.push_back(a[i] + 1);
	}

	return res;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	long long n, m;
	cin >> n >> m;
	m--;
	vector <int> res = solve(n, m);
	for (int i = 0; i < n; i++)
		cout << res[i] << " ";
	cout << endl;
	return 0;
}

#include <iostream>

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <cstring>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define itn int

#define NIE false
#define TAK true
///#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define matrix vector<vector<ll>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define dig(c) (c >=' 0' && c <= '9') ? 1 : 0
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--+--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const int MAXN = 300008;
const ll inf = 1000000001;
const ll INF = 2e18;
const ld EPS = 1e-7;
const ll mod = inf + 6;
const int moff = 998244353;

const int mod13 = 1000003;
const ld PI = acos(-1.0);

signed main()
{
	fastio();
	int n, m;
	cin >> n >> m;
	if (n == 3)
	{
		if (m == 1)
		{
			cout << " 1 2 3";
			return 0;
		}
		else if (m == 2)
		{
			cout << "1 3 2";
		}
		else if (m == 3)
		{
			cout << "2 3 1";
			return 0;
		}
		else if (m == 4)
		{
			cout << "3 2 1 ";
			return 0;
		}
	}
	int nw = 0;
	int mx = 0;
	vector<int> ans;
	for (int msk = 0; msk < (1 << (n / 2)); ++msk)
	{
		vector<int> now(n);
		for (int j = 0; j < (n / 2); ++j)
		{
			now[j] = j * 2 + 1;
			now[n - j - 1] = j * 2 + 2;
			if ((msk >> j) & 1) swap(now[j], now[n - j - 1]);
		}
		if (n % 2)
		{
			now[n / 2] = n;
		}
		nw++;
		if (nw == m)
		{
			vout(now, ' ');
			return 0;
			//	sp;
		}
	}
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#define ll long long int
#define pb push_back
#define mk make_par
#define mod 1000000007
using namespace std;

ll pow1(ll b)
{
    ll ans=1;
    for(ll a=1;a<=b;a++)
        ans=ans*2;
    return ans;
}

int main()
{
    int arr[55]={0};
    int i,j,k,l,n,m,ans=0,co=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        arr[i]=i;
    if(n<=8)
    {
        int mi=n+1;
        for(i=1;i<=n;i++)
        {
            mi=arr[i];
            for(j=i;j<=n;j++)
            {
                mi=min(arr[j],mi);
                ans+=mi;
            }
        }
        do
        {
            int temp=0;
            for(i=1;i<=n;i++)
            {
                mi=arr[i];
                for(j=i;j<=n;j++)
                {
                    mi=min(arr[j],mi);
                    temp+=mi;
                }
            }
            if(temp==ans)
            {
                co++;
            }
            if(co==m)
            {
                for(i=1;i<=n;i++)
                    cout<<arr[i]<<" ";
                break;
            }
        }
        while(next_permutation(arr+1,arr+n+1));
    }
    else
    {
        stack<int> st;
        vector<int> vec[10];
        vec[1].pb(n-2); vec[1].pb(n-1); vec[1].pb(n);
        vec[2].pb(n-2); vec[2].pb(n); vec[2].pb(n-1);
        vec[3].pb(n-1); vec[3].pb(n); vec[3].pb(n-2);
        vec[4].pb(n); vec[4].pb(n-1); vec[4].pb(n-2);

        for(i=1;i<=n-3;i++)
        {
            ll temp=pow1(n-i-1);
            cout<<temp<<"\n";
            if(m>temp)
            {
                st.push(i);
                m-=temp;
            }
            else
                cout<<i<<" ";
        }
        cout<<vec[m][0]<<" "<<vec[m][1]<<" "<<vec[m][2]<<" ";
        while(!st.empty())
        {
            int temp=st.top();
            cout<<temp<<" ";
            st.pop();
        }

    }

    return 0;
}

#include<iostream>
#include<vector>

using namespace std;

void f(int n, int m, int i, int j, vector<int>& a)
{
	int l{ j - i + 1 };
	if (l == 1)
	{
		a[i] = n - 1;
		return;
	}
	int c{ 1 << (l - 2) };
	if (m <= c)
	{
		a[i] = n - l;
		f(n, m, i + 1, j, a);
	}
	else
	{
		a[j] = n - l;
		f(n, m - c, i, j - 1, a);
	}
}
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	f(n, m, 0, n - 1, a);
	for (int i = 0; i < n; ++i)
		cout << ++a[i] << " \n"[i == n - 1];
}

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0, _n = (int)n; i < _n; i++)

int N;
long long M;

int P[55], Q[55], q;
bool used[55], used2[55];

int main()
{
    cin >> N >> M;
    M--;

    REP(i, N)
        P[i] = i;

    REP(i, N)
    {
        int j = 0;
        while (N-i-j-2 >= -1 && (1ll<<max(0, (N-i-j-2))) <= M)
        {
            M -= (1ll<<max(0, (N-i-j-2)));
            j++;
        }

        if (i) cout << " ";
        cout << P[j]+1;

        used[P[j]] = true;

        q = 0;
        for (int k = j+1; k < N; k++)
        {
            if (!used[P[k]])
            {
                used2[P[k]] = true;
                Q[q++] = P[k];
            }
            if (P[k] == N-1)
                break;
        }

        for (int k = N-1; k >= 0; k--)
            if (!used2[P[k]] && !used[P[k]])
                Q[q++] = P[k];

        REP(i, N)
        {
            used2[i] = false;
            P[i] = Q[i];
        }
    }

    cout << endl;
}

#include<iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n,m;
    cin >>n >>m;
    int a[n];
    //a[0]=1;
    for(int i=0;i<n;i++)
        a[i] =i+1;
    //for (int j=0;j<n;j++)
                //cout << a[j] << " ";

    int countt=1;
    while ( next_permutation (a,a+n))
    {
        //cout<< "inside while" << endl;
        countt++;
        //cout<< "countt" << countt << endl;
        if(countt==m)
        {
            for (int j=0;j<n;j++)
                cout << a[j] << " ";

            break;
        }
    }
    return 0;
}

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

int main() {

    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int n, m;

    cin >> n >> m;

    vector<int> data(n);

    long long count = 1LL << (n - 1);

    int left = 0, right = n - 1;

    for(int i = 1; i <= n; ++i) {
        if(m <= count / 2LL) {
            data[left] = i;
            ++left;
        } else {
            data[right] = i;
            --right;
            m -= count / 2;
        }
        count /= 2;
    }

    for(int i = 0; i < n; ++i) {
        cout << data[i] << ' ';
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll>
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size()
#define ara cout<<"ara-ara\n";

void func()
{
  ll n,m;
  cin>>n>>m;

  ll l=1,r=n,curr=1,ans[n+1];
  while(curr<=n)
  {
    if(l==r)
    {
      ans[l]=curr;
      break;
    }

    ll rem=n-curr;
    if((1<<(rem-1))>=m)
    {
        ans[l]=curr;
        l++;
    }
    else
    {
        m-=(1<<(rem-1));
        ans[r]=curr;
        r--;
    }
    curr++;
  }
  f(i,1,n+1) cout<<ans[i]<<" ";
  cout<<"\n";

}

int main()
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE

    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
       func();
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

map<string,int> points;
map<string,vector<int>> pos;

string checkPos()
{
    int posi=1;
    vector<string> good;
    for(auto i:pos) good.pb(i.ff);

    while(sz(good)>1)
    {
        int maxx=0;
        for(auto i:good)
        {
            int c=0;
            for(auto j:pos[i])
            {
                if(j==posi) c++;
            }
            maxx=max(c, maxx);
        }
        string s;
        int cnt=0;
        vector<string> temp;
        for(auto i:good)
        {
            int c=0;
            for(auto j:pos[i])
            {
                if(j==posi)
                {
                    c++;
                }
            }
            if(c==maxx)
            {
                temp.pb(i);
            }
        }
        good=temp;
        posi++;
    }
    return good[0];
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;
    cin>>t;
    int pts[]={25, 18, 15, 12, 10, 8, 6, 4, 2, 1};

    ffor(i,0,t)
    {
        int n;
        cin>>n;
        ffor(i,0,n)
        {
            string s;
            cin>>s;
            points[s]+=pts[i];
            pos[s].pb(i+1);
        }
    }
   // cout<<checkPos()<<endl;

    int maxx=0;
    for(auto i:points)
    {
        maxx=max(maxx,i.ss);
    }
    string s;
    int c=0;

    for(auto i:points)
    {
        if(i.ss==maxx)
        {
            c++;
            s=i.ff;
        }
    }
    if(c==1) cout<<s<<endl;
    else {cout<<checkPos()<<endl;}

    map<string,int> wins;
    for(auto i:pos)
    {
        int c=0;
        for(auto j:i.ss) if(j==1) c++;
        wins[i.ff]=c;
    }

    maxx=0;
    for(auto i:wins)
    {
        maxx=max(maxx,i.ss);
    }
    c=0;
    for(auto i:wins)
    {
        if(i.ss==maxx)
        {
            c++;
            s=i.ff;
        }
    }

    if(c==1) cout<<s;
    else
    {
        maxx=0;
        for(auto i:points)
        {
            maxx=max(maxx,i.ss);
        }
        c=0;
       // cout<<maxx<<endl;
        for(auto i:points)
        {
            if(maxx==i.ss)
            {
                s=i.ff;
                c++;
               // cout<<s<<endl;
            }
        }
        if(c==1) cout<<s;
        else cout<<checkPos();
    }

    return 0;
}

#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pob         pop_back
#define ins         insert
#define fi          first
#define se          second
#define inf         200001
#define rep(a,b,c)  for(ll i=a;i<b;i=i+c)
#define repd(a,b,c) for(ll i=a;i>b;i=i-c)
#define Arena       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii         pair<ll,ll>
#define mod         1000000007
#define N           100001
#define si(n)       scanf("%s",&n)
vector<pii>v;
ll arr[100];
ll n,m;
ll cnt=0;
int way(ll ans[],ll index,ll f){
    //cout<<index<<" "<<f<<endl;
    if(index==(n/2)){
        //cout<<"D";
        cnt++;
        if(cnt>=m){
            //cout<<"E";
            for(int i=1;i<=n;i++){
                arr[i]=ans[i];
            }
            return 1;
        }
        return 0;
    }
    //cout<<"A";
    ans[f]=v[index].fi;
    //cout<<"B";
    ans[f+1]=v[index].se;
    //cout<<"C";
    if(way(ans,index+1,f+2)){
        return 1;
    }
    ans[f]=-1;
    ans[f+1]=-1;
    ans[f]=v[index].fi;
    ans[f+n-v[index].fi]=v[index].se;
    if(index==((n/2)-1) && n!=3){
        swap(ans[f],ans[f+n-v[index].fi]);
    }
    if(way(ans,index+1,f+1)){
        return 1;
    }
    ans[f]=-1;
    ans[f+n-v[index].fi]=-1;
    return 0;
}
int main(){
    cin>>n>>m;
    bool flag=true;
    ll total=2*pow(2,n/2);
    if(m>(total/2)){
        flag=false;
        m=total-m+1;
    }
    //vector<pii>v;
    for(ll i=1;i<n;i+=2){
        v.pb({i,i+1});
    }
    ll ans[n+1];
    for(ll i=1;i<=n;i++){
        ans[i]=-1;
    }
    way(ans,0,1);
    if(n%2==1){
        for(ll i=1;i<=n;i++){
            if(arr[i]==-1){
                arr[i]=n;
            }
        }
    }
    if(flag){
        for(ll i=1;i<=n;i++){
            cout<<arr[i]<<" ";
        }
    }
    else{
        for(ll i=n;i>=1;i--){
            cout<<arr[i]<<" ";
        }
    }
    return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ld long double
#define eb emplace_back
#define ll int32_t
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int32_t , int32_t >
#define Endl '\n'
#define pll pair <ll,ll>
using namespace std;
using namespace __gnu_pbds;
typedef tree <pair <pll,ll> ,null_type,less <pair <pll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set2;
mt19937_64 randomizer(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
const int mod = 1e9+7;
const int number_for_MO = 1e4+111;
const int size_for_segment_trees = 1e6;
const int32_t FFTM = 998244353;
const int32_t N = 50000;
int32_t SX[4] = {0 , 1 , -1 , 0};
int32_t SY[4] = {1 , 0 , 0 , -1};
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef CHUCHUNDRA
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ll n,m;
cin>>n>>m;
--m;
vector <ll> a(n);
ll left = 0;
ll right = n - 1;
ll pointer = 1;
for (int j = 0;j < n;j++)
    {
        if (m>=(1LL)<<(n-j-2)) {
                m-=((1LL)<<(n-j-2));
        a[right] = j + 1;
        --right;
    }
    else {
        a[left] = j + 1;
        ++left;
    }
    ++pointer;
    }
for (int i = 0;i < n;i++)
    cout<<a[i]<<" ";
return 0;
}
/*
Я всё вижу, чучундры! ;=)
*/
/*
Я всё слышу, чучундры! ;=)
*/

#include<bits/stdc++.h>
#include <stdio.h>

using namespace std;

#define mod 1000000007LL
#define pi 3.141592653589793238462643383279;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second

int main()
{
    int n,m;
    cin>>n>>m;
    m--;
    //vector<i>
    vector<bool> temp(n+1,false);
    for(int i=n;i>=2;i--)
    {
        if(m&(1<<(i-2)))
           {
               m-=(1<<(i-2));
               temp[n-i+1]=true;
           }
           else
            cout<<n-i+1<<" ";
    }
    temp[n]=true;
    for(int i=n;i>=1;i--)
    {
        if(temp[i])
            cout<<i<<" ";
    }
    int acc;cin>>acc;
    return 0;
}

/*
    Tanvir Hasan Anick
    University of Asia pacific
*/
/**Header file**/
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<stack>
#include<list>
#include<iostream>
#include<assert.h>

/**Define file I/O **/
#define f_input freopen("input.txt","r",stdin)
#define f_output freopen("output.txt","w",stdout)

/**Define memory set function**/
#define mem(x,y) memset(x,y,sizeof(x))
#define CLEAR(x) memset(x,0,sizeof(x))

/**Define function and object**/
#define pb push_back
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v) sort(v.rbegin(),v.rend())
#define CSort(v,C) sort(v.begin(),v.end(),C)
#define all(v) (v).begin(),(v).end()
#define sqr(x) ((x)*(x))
#define find_dist(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))

/**Define constant value**/
#define ERR 1e-9
#define pi (2*acos(0))
#define PI 3.141592653589793

/**Define input**/
#define scanint(a) scanf("%d",&a)
#define scanLLD(a) scanf("%lld",&a)
#define scanstr(s) scanf("%s",s)
#define scanline(l) scanf(" %[^\n]",l);

/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))

/**Define color**/
#define WHITE 0
#define GREY 1
#define BLACK 2

/**Sync off with stdio**/
#define __ cin.sync_with_stdio(false);\
           cin.tie();
/**Debug tools**/
#define what_is(x) cerr<<(#x)<<" is "<<x<<endl
using namespace std;

/**Typedef**/
typedef vector<int> vint;
typedef vector< vint > vint2D;
typedef vector<string> vstr;
typedef vector<char>vchar;
typedef vector< vchar >vchar2D;
typedef queue<int> Qi;
typedef queue< Qi > Qii;
typedef map<int,int> Mii;
typedef map<string,int> Msi;
typedef map<int,string> Mis;
typedef stack<int> stk;
typedef pair<int,int> pp;
typedef pair<int, pp > ppp;
typedef long long int LLD;
const int inf=0x7FFFFFFF;

/**Template & structure**/
struct point_int{int x,y;point_int(){}point_int(int a,int b){x=a,y=b;}}; ///Point for x,y (int) coordinate in 2D space
struct point_double{double x,y;point_double(){}point_double(double a,double b){x=a,y=b;}}; ///Point for x,y (double) coordinate in 2D space
struct Node{int v,w;Node() {}bool operator<(const Node &a)const{return w>a.w;}Node(int _v,int _w){v=_v,w=_w;}};///Node for Dijkstra
namespace my{
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T>T multiplication(T n,T p,T m){if(p==0)return (T)0;T x=multiplication(n,p/2,m);x=(x+x)%m;if(p&1)x=(x+n)%m;return x;}
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}/// distance between a & b
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}/// convert a number to string
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));} /// minimum of 3 number
template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));} ///maximum of 3 number
template <class T> void print_vector(T &v){int sz=v.size();if(sz)cout<<v[0];for(int i = 1; i < sz; i++)cout << ' '<<v[i];cout<<endl;}/// prints all elements in a vector
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConsonant(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}}
/**Shortcut input function**/
int read_int(){int n;scanf("%d",&n);return n;}
int read_LLD(){LLD n;scanf("%lld",&n);return n;}
inline int buffer_input() { char inp[1000]; scanstr(inp); return atoi(inp); }

/**Direction**/
///int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ///8 Direction
///int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1}; ///4 Direction
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; ///Hexagonal Direction

/******************************Ajaira Jinish Sesh******************************/
vint v;
int F(const vector<int>&v)
{
    int sum=0;
    int sz=v.size();
    for(int i=0;i<sz;i++)
    {
        for(int j=i;j<sz;j++)
        {
            int m=inf;
            for(int k=i;k<=j;k++)
            {
                m=min(v[k],m);
            }
            sum+=m;
        }
    }
    return sum;
}
int main()
{
    #ifdef _ANICK_
    //f_input;
    #endif // _ANICK_
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)v.pb(i);
    int f=0;
    int cnt=0;
    vint ans;
    do
    {
        int m=F(v);
        if(m>=f)
        {
            ans=v;
            f=m;
        }
        cnt++;
        if(cnt==k)break;
    }while(next_permutation(all(v)));
    my::print_vector(ans);
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <deque>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:268435456")
#define ll long long
#define ff first
#define ss second

const int maxn = 100001;
const ll inf = 2147483647;

ll a[50000][51], ans[50000], numb = 0;
ll n, m;

void gener(vector<ll> c, vector<ll> b)
{
	vector<ll> d, e;
	if (c.size() == n)
	{
		for (int i = 0; i < n; ++i)
			a[numb][i] = c[i];
		++numb;
		return;
	}
	for (int i = 0; i < b.size(); ++i)
	{
		d = c;
		e = b;
		d.push_back(e[i]);
		e.erase(e.begin() + i);
		gener(d, e);
	}
}

int main()
{
	cin.sync_with_stdio(0);
	vector<ll> b, c;
	ll step[51];
	ll minn, maxx = 0;
	deque<ll> d;
	cin >> n >> m;
	step[0] = 1;
	for (int i = 1; i < 51; ++i)
		step[i] = step[i - 1] * 2;
	d.push_back(n);
	for (int i = n - 2; i >= 0; --i)
	{
		if (m > step[i])
		{
			m -= step[i];
			d.push_front(i + 1);
		}
		else
			d.push_back(i + 1);
	}
	for (int i = 0; i < n; ++i)
		cout << d[i] << ' ';
	/*for (int i = n; i > 0; --i)
		b.push_back(i);
	gener(c, b);
	for (int i = 0; i < 50000; ++i)
		ans[i] = 0;
	for (int i = 0; i < numb; ++i)
		for (int j = 0; j < n; ++j)
			for (int k = j; k < n; ++k)
			{
				minn = inf;
				for (int h = j; h <= k; ++h)
				{
					if (minn > a[i][h])
						minn = a[i][h];
				}
				ans[i] += minn;
			}
	for (int i = 0; i < numb; ++i)
		if (maxx < ans[i])
			maxx = ans[i];
	for (int i = 0; i < numb; ++i)
		if (maxx == ans[i])
		{
			for (int j = 0; j < n; ++j)
				cout << a[i][j] << ' ';
			cout << '\n';
		}*/
	return 0;
}
/*

*/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <vector>
#include <stack>
using namespace std;
#define fi "input.txt"
#define fa "output.txt"
#define foru(i,l,r) for(int i=l;i<r;i++)
#define ford(i,l,r) for(int i=l;i>r;i--)
#define ll long long
#define re return
#define pb push_back

const int maxN=101000;
int n,m,a[100],b[100],res;

bool fr[maxN];

void init() {
    cin>>n>>m;
}

void xuat(int l,int r) {
    if (l<=0 || r<=0) re;
    if (l<=r) foru(i,l,r+1) printf("%i ",i); else ford(i,l,r-1) printf("%i ",i);
}

void dq(int k) {
    if (k>n) {
        int ans=0;
        foru(i,1,n+1) {
            int ht=n+1;
            foru(j,i,n+1) {
                ht=min(ht,a[j]);
                ans+=ht;
            }
        }
        res=max(ans,res);
        re;
    }
    foru(i,1,n+1) if (b[i]==0) {
        b[i]=1;
        a[k]=i;
        dq(k+1);
        b[i]=0;
    }
}

void dq1(int k) {
    if (k>n) {
        int ans=0;
        foru(i,1,n+1) {
            int ht=n+1;
            foru(j,i,n+1) {
                ht=min(ht,a[j]);
                ans+=ht;
            }
        }
        if (ans==res) {
            --m;
            if (m!=0) re;
            foru(i,1,n+1) printf("%i ",a[i]);
            cout<<"\n";
        }
        re;
    }
    foru(i,1,n+1) if (b[i]==0) {
        b[i]=1;
        a[k]=i;
        dq1(k+1);
        b[i]=0;
    }
}

void xuly() {
    //if (m>4) foru(i,0,1000000000) cout<<i;
    int tm=m;
//    dq(1);
//    cout<<res<<"\n";
//    dq1(1);
    int l=1,r=n;
    int ht=1;
    memset(fr,true,sizeof(fr));
    memset(a,0,sizeof(a));
    tm--;
    foru(i,0,n) {
        if ((tm>>(n-i-2))%2==1) a[r--]=i+1; else a[l++]=i+1;
    }
    ford(i,n,0) if (a[i]==0) {
        foru(j,1,n+1) if (fr[j]) {
            fr[j]=false;
            a[i]=j;
            break;
        }
    }
    foru(i,1,n+1) printf("%i ",a[i]);
}

int main() {
    //freopen(fi,"r",stdin);
//    freopen(fa,"w",stdout);
    init();
    xuly();
    fclose(stdin);
    fclose(stdout);
    re 0;

}

#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int n,a[10],i,j,k;
long long ts;

int main()
{
    scanf("%d%lld",&n,&ts);
    i=0;
    j=n-1;
    for(k=n-1;k>=0;k--)
        if(ts>>k&1)
        {
            a[j]=n-k;
            j--;
        }
        else
        {
            a[i]=n-k;
            i++;
        }
    for(i=0;i<n;i++)
        printf("%d%c",a[i],i==n-1?'\n':' ');
    return 0;
}

 /*
 LANG : C++
 */
 # include <iostream>
 # include <cstdio>
 # include <cstdlib>
 # include <algorithm>
 # include <cstring>
 # include <map>
 # include <set>
 # include <vector>

 # define FOR(xxx, yyy, zzz) for(long long xxx = yyy; xxx <= zzz; ++xxx)
 # define f first
 # define s second
 # define pb push_back
 # define mp make_pair

 using namespace std;

 typedef long long ll;

 ll a[60], f[60];
 ll n, m;

 set < pair<ll, ll> > st;

 void rec (ll x) {
     st.clear ();
     if (x == n + 1) {
        FOR (i, 1, n)
        cout << a[i] << ' ';
        return;
     }
    /* FOR (i, 1, n)
     cout << a[i] << ' ';
     cout << endl;*/
     FOR (i, 1, n) {
        if (!a[i]) {
            ll pr = i;
            while (a[pr] == 0 && pr >= 1) pr --; pr ++;
            ll nx = i;
            while (a[nx] == 0 && nx <= n) nx ++; nx --;
            st.insert (mp ((nx - i + 1) * (i - pr + 1), i));
         //   cout << (nx - i + 1) * (i - pr + 1) << ' ' << i << ' ' << x << endl;
        }
     }
    // cout << f[n - x] << endl;
    // if (pos == 0) pos ++;
    ll pos = 1;

    if (n - x <= 25)
     pos = (m + f[n - x] - 1) / f[n - x];

    if (m >= f[n - x])
        m %= f[n - x];
    //pos = 1;
     if (m == 0) m = 1;
     //cout << pos << endl;
     for (set < pair<ll, ll> > :: iterator it = st.begin (); it != st.end (); ++it) {
        pos --;
        if (pos == 0)  {
       //         cout << (it -> s) << endl;
            a[(it -> s)] = x;
            rec (x + 1);
            break;
        }
     }
 }

 int main () {
     cin >> n >> m;
     f[0] = 1;
     FOR (i, 1, 25)
     f[i] = i * f[i - 1];
     rec (1);
 }

#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#include <limits.h>
#include <algorithm>
#include <set>
#include <ctime>
#include <assert.h>
using namespace std;
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i=a; i<(int)n; i++)
#define per(i,n,a) for (int i=n; i>=a; i--)
#define hk push_back
#define pk pop_back
#define mp make_pair
#define PI 3.141592653589793
#define clr(a) memset(a, 0, sizeof(a))
#define clr1(a) memset(a, -1, sizeof(a))
typedef vector<int> VI;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, pair<int, double> > > VPIPID;
typedef vector<string> VS;
typedef vector <double> VD;
typedef vector <bool> VB;
typedef long long ll;
#define MAX_V 1000
const ll mod = 1000000007;
const int INF = 987654321;
ll powmod(ll a, ll b) {
	ll res = 1; a %= mod; for (; b; b >>= 1){ if (b & 1)res = res*a%mod; a = a*a%mod; }return res;
}

ll T, n, m;
int p[10];

void permutation(VB visited, int k, int left){
	if (left < 1) return;
	int idx = (left > 1)? k / p[left - 1] : k;
	if (left > 1 && k % p[left - 1]) idx++;
	int idxTmp = idx;
	rep(i, 0, visited.size()){
		if (!visited[i]) {
			idx--;
		}
		if (idx == 0) {
			visited[i] = true;
			cout << i + 1 << " ";
			permutation(visited, k - (idxTmp - 1) * p[left - 1], left - 1);
			break;
		}
	}
}

int main()
{
	int tmp = 1;
	rep(i, 1, 10){
		p[i] = tmp;
		tmp *= i + 1;
	}
	cin >> n >> m;
	VB visited(n, 0);
	permutation(visited, m, n);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(i=(x);i<=(y);++i)
#define repd(i,x,y) for(i=(x);i>=(y);--i)
#define irep(i,x,y) for(int i=(x);i<=(y);++i)
#define irepd(i,x,y) for(int i=(x);i>=(y);--i)
#define foreach(it,g) for(__typeof((g).begin())it=(g).begin();it!=(g).end();++it)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
#define trace(x) cerr<<#x<<" = "<<(x)<<"\n"
#define tracearr(a,n) {cout<<#a<<" = ";irep(__,1,n)cout<<a[__]<<" ";cout<<"\n";}
#define traceeach(a) {cout<<#a<<" = ";foreach(__,a)cout<<*__<<" ";cout<<"\n";}
#define sqr(x) ((x)*(x))
#define abs(x) ((x)<0?(-(x)):(x))
typedef long long ll;
const ll mod=1000000007;
const double pi=acos(-1.0);
int val,sgn; char sym;
int getint() {
    val=0; sgn=1;
    do { sym=getchar(); } while (sym<=32);
    if (sym=='-') { sgn=-1; sym=getchar(); }
    while (sym>='0' && sym<='9') { val=(val<<3)+(val<<1)+sym-48; sym=getchar(); }
    return val*sgn;
}

int n,m,i,p,Bit[4444];

int main () {
srand(time(NULL));
//freopen("input.txt","r",stdin);
    cin >> n>>m;
    p=1; --m;
    while(m) {Bit[p]=m%2;m/=2;++p;}
    rep(i,1,n) if(!Bit[n-i]) cout<<i<<' ';
    repd(i,n,1) if (Bit[n-i]) cout <<i<<' ';
    cout <<"\n";

    return 0;

}

#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>

using namespace std;
int n,m,i,x;
vector<pair<int,vector<int> > >v;
vector<int >a;
int run()
{
    int sc=0,aux=100;
    for(int i=0;i<n;i++)
        for(int j=i;j<n;j++)
    {
        for(int k=i;k<=j;k++)
            aux=min(aux,a[i]);
        sc+=aux;
    }
    return aux;
}
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++)
        a.pb(i);
    v.push_back(mp(x,a));
    while(next_permutation(a.begin(),a.end()))
    {
        x=run();
        v.pb(mp(x,a));
    }
    sort(v.begin(),v.end());
    for(auto it:v[m-1].second)
    {
        cout<<it<<' ';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	long long m;
	vector <bool> per;
	vector <int> res;
	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		res.push_back(i);
	}
	m--;
	while(m){
		next_permutation(res.begin(),res.end());
		m--;
	}
	cout << res[0];
	for(int i = 1; i < (int)res.size(); i++){
		cout << " " << res[i];
	}
	cout << endl;
}

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#define sz 20
using namespace std;

int n, ok[sz], a[sz], co, z, ma = 0, k , zz, b[200000][10];

void rec(int v) {
    if (v > n) {
    	zz=0;
    	for (int i=1; i<n; i++)
    		for (int j=i+1; j<=n; j++)  {
    			int mi=a[i];
    			if (a[j]<mi) mi=a[j];
    			zz+=mi;
    		}
    	if (zz>ma) ma=zz;
    	co++;
    	for (int i=1; i<=n; i++)
    		b[co][i]=a[i];
    	b[co][n+1]=zz;
    } else {
        for (int i = 1; i <= n; i++)
            if (!ok[i]) {
                ok[i] = 1;
                a[v] = i;
                rec(v+1);
                ok[i] = 0;
            }
    }
}

int main()
{

    cin>>n>>k;

    rec(1);
    z=0;
    for (int i=1; i<=co; i++)  {
    	if (b[i][n+1]==ma) z++;
    	if (z==k) {
    		for (int j=1; j<=n; j++)
    			cout<<b[i][j]<<" ";
    		exit(0);
    	}

    }
    return 0;
}

#include <stdio.h>
using namespace std;
int n,m,i,k,t[15];
int main(){
scanf("%d%d",&n,&m);
k=1; m--;
while (m>0) {
t[k++]=m%2;
m=m/2;
}
for (i=1;i<=n;i++)
    if (t[n-i]==0) printf("%d ",i);
for (i=n;i>=1;i--)
    if (t[n-i]==1) printf("%d ",i);
return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0, _n = (int)n; i < _n; i++)

int N;
long long M;

int P[55], Q[55], q;
bool used[55], used2[55];

int main()
{
    cin >> N >> M;
    M--;

    REP(i, N)
        P[i] = i;

    REP(i, N)
    {
        int j = 0;
        while (N-i-j-2 >= -1 && (1ll<<max(0, (N-i-j-2))) <= M)
        {
            M -= (1ll<<max(0, (N-i-j-2)));
            j++;
        }

        if (i) cout << " ";
        cout << P[j]+1;

        used[P[j]] = true;

        q = 0;
        for (int k = j+1; k < N; k++)
        {
            if (!used[P[k]])
            {
                used2[P[k]] = true;
                Q[q++] = P[k];
            }
            if (P[k] == N-1)
                break;
        }

        for (int k = N-1; k >= 0; k--)
            if (!used2[P[k]] && !used[P[k]])
                Q[q++] = P[k];

        REP(i, N)
        {
            used2[i] = false;
            P[i] = Q[i];
        }
    }

    cout << endl;
}

#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int n, m;
int ans[100];

int main() {
    scanf("%d %d", &n, &m);
    m--;

    int l = 0;
    int r = n - 1;
    int free = 1;

    for(int i = n - 1 - (n & 1); i >= 0; i--) {
            if ((m >> i) & 1) {
                   ans[l] = free;
            } else {
                   ans[l] = free;
            }
            free += 1;
            l++;
    }

    if (n & 1) ans[n / 2] = n;

    for(int i = 0; i < n; i++) {
            printf("%d ", ans[i]);
    }

    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
void comb(int i, int n, int m, int cur[], int curLen)
{
    if (curLen == m)
    {
        for (int j = 0; j < m; ++j)
            cout << cur[j]+1;
        cout << "\n";
        return;
    }

    if (i == n)
        return;

    cur[curLen] = i;
    comb(i + 1, n, m, cur, curLen + 1);
    comb(i + 1, n, m, cur, curLen);
}
int cur[10000];
int main() {
    int n,m ;

    int arr[10000];
    cin >> n >> m; m--;
    for (int i = 0; i < n; i++)arr[i]=i+1;
    do {
        if (!m--)break;
    } while (std::next_permutation(arr, arr + n));

    for (int i = 0; i < n; i++)cout << arr[i] << " ";;

    return 0;
}/*
int main()
{

    comb(0, 3, 2 , cur, 0);
}*/

//int main()
//{
//  countcomp(0, 2, 2, cur, 0);
//
//
//
//
//  /*int n, m, k1, k2; cin >> n >> m >> k1 >> k2;
//  while (n&&m)
//  {
//      n--;
//      if (!n)break;
//      m--;
//  }
//  if (m<=0)
//      cout << "First" << endl;
//  else
//  cout << "Second" << endl;
//  return 0;*/
//}

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0, _n = (int)n; i < _n; i++)

int N;
long long M;

int P[55], Q[55], q;
bool used[55], used2[55];

int main()
{
    cin >> N >> M;
    M--;

    REP(i, N)
        P[i] = i;

    long long wow = 1ll<<(N-2);

    REP(i, N)
    {
        int j = 0;
        while (wow <= M)
        {
            M -= wow;
            wow /= 2;
            j++;

            if (wow == 0)
                break;
        }

        if (wow == 0)
        {
            for (int k = N-1; k >= 0; k--)
                if (!used[k])
                    cout << k+1 << " ";
            cout << endl;
            return 0;
        }

        cout << P[j]+1 << " ";

        wow /= 2;
        if (wow == 0)
            wow = 1;

        used[P[j]] = true;

        q = 0;
        for (int k = P[j]+1; k < N; k++)
        {
            if (!used[k])
            {
                used2[k] = true;
                Q[q++] = k;
            }
        }

        for (int k = N-1; k >= 0; k--)
            if (!used2[P[k]] && !used[P[k]])
                Q[q++] = P[k];

        REP(i, N)
        {
            used2[i] = false;
            P[i] = Q[i];
        }
    }

    cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
int n, a[10], m;

int main(){
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) a[i] = i + 1;

  int p[10], res = 0;
  while (m--){
    int sum = 0;
    int mi[10][10];
    for (int i = 0; i < n; i++){
      for (int j = i; j < n; j++){
        if (i == j) mi[i][j] = a[i];
        else mi[i][j] = min(mi[i][j-1], a[j]);
      }
    }
    for (int i = 0; i < n; i++){
      for (int j = i; j < n; j++) sum += mi[i][j];
    }
    if (res <= sum){
      res = sum;
      for (int i = 0; i < n; i++) p[i] = a[i];
    }
    if (next_permutation(a, a + n)) continue;
    break;
  }
  for (int i = 0; i < n; i++) printf("%d ", p[i]);
}

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int n ;
int arr[9];

int f (vector<int> x)
{
    int mn = 2e9;
    int last = 0;
    int out = 0;
    for(int i = 0 ; i < n ; i++)
    {

        last = 0;
        mn = 2e9;
        for(int j = i ; j < n ; j++)
        {
            mn = min(mn , x[j]);
            last += mn;
        }
        cout << i << " " << last << endl;
        out += last;
    }
    return out ;

}
int main() {

    int  m;
    cin >> n >> m;

    for(int i = 0 ; i < n ; i++)
        arr[i] = i + 1;

    vector < pair<int,vector<int> > > perm;

    do {
        vector <int> temp;
        for(int i = 0 ; i < n ; i++)
            temp.push_back(arr[i]);
        perm.push_back({f(temp),temp});
    } while (next_permutation(arr , arr + n) );
    sort(perm.begin() , perm.end());

    for(int i = 0 ; i < n ; i++)
        cout << perm[m - 1 ].second[i] << " ";
    cout << endl;
    return 0;
}

/*
    Tanvir Hasan Anick
    University of Asia pacific
*/
/**Header file**/
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<stack>
#include<list>
#include<iostream>
#include<assert.h>

/**Define file I/O **/
#define f_input freopen("input.txt","r",stdin)
#define f_output freopen("output.txt","w",stdout)

/**Define memory set function**/
#define mem(x,y) memset(x,y,sizeof(x))
#define CLEAR(x) memset(x,0,sizeof(x))

/**Define function and object**/
#define pb push_back
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v) sort(v.rbegin(),v.rend())
#define CSort(v,C) sort(v.begin(),v.end(),C)
#define all(v) (v).begin(),(v).end()
#define sqr(x) ((x)*(x))
#define find_dist(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))

/**Define constant value**/
#define ERR 1e-9
#define pi (2*acos(0))
#define PI 3.141592653589793

/**Define input**/
#define scanint(a) scanf("%d",&a)
#define scanLLD(a) scanf("%lld",&a)
#define scanstr(s) scanf("%s",s)
#define scanline(l) scanf(" %[^\n]",l);

/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))

/**Define color**/
#define WHITE 0
#define GREY 1
#define BLACK 2

/**Sync off with stdio**/
#define __ cin.sync_with_stdio(false);\
           cin.tie();
/**Debug tools**/
#define what_is(x) cerr<<(#x)<<" is "<<x<<endl
using namespace std;

/**Typedef**/
typedef vector<int> vint;
typedef vector< vint > vint2D;
typedef vector<string> vstr;
typedef vector<char>vchar;
typedef vector< vchar >vchar2D;
typedef queue<int> Qi;
typedef queue< Qi > Qii;
typedef map<int,int> Mii;
typedef map<string,int> Msi;
typedef map<int,string> Mis;
typedef stack<int> stk;
typedef pair<int,int> pp;
typedef pair<int, pp > ppp;
typedef long long int LLD;
const int inf=0x7FFFFFFF;

/**Template & structure**/
struct point_int{int x,y;point_int(){}point_int(int a,int b){x=a,y=b;}}; ///Point for x,y (int) coordinate in 2D space
struct point_double{double x,y;point_double(){}point_double(double a,double b){x=a,y=b;}}; ///Point for x,y (double) coordinate in 2D space
struct Node{int v,w;Node() {}bool operator<(const Node &a)const{return w>a.w;}Node(int _v,int _w){v=_v,w=_w;}};///Node for Dijkstra
namespace my{
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T>T multiplication(T n,T p,T m){if(p==0)return (T)0;T x=multiplication(n,p/2,m);x=(x+x)%m;if(p&1)x=(x+n)%m;return x;}
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}/// distance between a & b
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}/// convert a number to string
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));} /// minimum of 3 number
template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));} ///maximum of 3 number
template <class T> void print_vector(T &v){int sz=v.size();if(sz)cout<<v[0];for(int i = 1; i < sz; i++)cout << ' '<<v[i];cout<<endl;}/// prints all elements in a vector
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConsonant(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}}
/**Shortcut input function**/
int read_int(){int n;scanf("%d",&n);return n;}
int read_LLD(){LLD n;scanf("%lld",&n);return n;}
inline int buffer_input() { char inp[1000]; scanstr(inp); return atoi(inp); }

/**Direction**/
///int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ///8 Direction
///int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1}; ///4 Direction
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; ///Hexagonal Direction

/******************************Ajaira Jinish Sesh******************************/
vint v;
vector< vector<int> >Store[100000];
int F(const vector<int>&v)
{
    int sum=0;
    int sz=v.size();
    for(int i=0;i<sz;i++)
    {
        for(int j=i;j<sz;j++)
        {
            int m=inf;
            for(int k=i;k<=j;k++)
            {
                m=min(v[k],m);
            }
            sum+=m;
        }
    }
    return sum;
}
int main()
{
    #ifdef _ANICK_
    //f_input;
    #endif // _ANICK_
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)v.pb(i);
    int f=0;
    int cnt=0;
    vint ans;
    do
    {
        f=max(f,F(v));
        Store[f].pb(v);
    }while(next_permutation(all(v)));
    my::print_vector(Store[f][k-1]);
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<stdlib.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
//set<string> mySet;
void permutations(string s,int m)
{
    int counter = 0;
    bool done = 0;
    while (next_permutation(s.begin(), s.end())) {
        if (counter == m) {
            for (int i = 0; i < s.size(); i++)
            {
                cout << s[i];
                if (i < s.size() - 1)
                    cout << " ";
            }
            return;
        }
        for (int i = 0; i < s.size(); i++)
        {
            cout << s[i];
            if (i < s.size() - 1)
                cout << " ";
        }
        counter++;
    }
}
int main()
{
    int n, m;
    cin >> n >> m;
    m -= 2;
    char index = '1';
    string s = "";
    for (int i = 0; i < n; i++)
    {
        s += index;
        index++;
    }
    if (m == -1) {
        for (int i = 0; i < s.size(); i++)
        {
            cout << s[i];
            if (i < s.size() - 1)
                cout << " ";
        }
    }
    else {
        //mySet.insert(s);
        permutations(s, m);
    }
    /*m--;
    set<string>::iterator myIt=mySet.begin();
    while (m>0)
    {
        myIt++;
        m--;
    }
    for (int i = 0; i < (*myIt).size(); i++)
    {
        cout << (*myIt)[i];
        if (i < (*myIt).size() - 1)
            cout << " ";
    }
    cout << endl;*/
    //system("pause");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

long long x , y , z , i , j , n , m , k , s1 , s2 , s3 , s4 , s5 , mod , l , r , t , maxx , minn , sx , so , sum ;
double u , v , w , x1 , x2 , x3 , z1 , z2 , z3 , h , huh ;
long long a [ 3000045 ] ;
long long b [ 3000045 ] ;
long long c [ 3000045 ] ;
long long d [ 1000045 ] ;
pair < long long , long long > aa [ 300045 ] ;
string s ;
string q ;
string p ;
string poop ;
char ch ;
vector < long long > vc ;
queue < string > qu ;
map < long long , long long > mp ;
map < long long , long long > pm ;

int main() {
    scanf ( "%lld%lld" , & n , & m ) ;
    l = 0 ;
    r = n ;
    x = 1 ;
    for ( i = 0 ; i <= n ; i ++ ) {
        b [ i ] = x ;
        x *= 2 ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
        x = r - l - 2 ;
        if ( m <= b [ x ] ) {
            a [ l ] = i ;
            l ++ ;
        }
        else {
            r -- ;
            a [ r ] = i ;
            k -= b [ x ] ;
        }
    }
    for ( i = 0 ; i < n ; i ++ ) {
        printf ( "%lld " , a [ i ] ) ;
    }
}

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int n, m, A[51];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        A[i] = i + 1;
    }
    while (--m)
        next_permutation(A, A + n);
    for (int i = 0; i < n; i++) {
        printf("%d ", A[i]);
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

long long num,m;
int a[55];

void call(int l,int r,int m){
    if(m == 0 || m == 1)return;
    //cout<<l<<" "<<r<<" "<<m<<endl;
    long long counter=0;
    for(int i=r;i>=l;i--){
        if((1 << counter) > m){

            int temp=a[i];
            for(int j=i;j<r;j++)a[j]=a[j+1];
            a[r]=temp;
            call(i,r-1,m-(1<<(counter-1)));
            break;
        }
        else if( (1 << counter)  == m){
            while(i < r ){
                swap(a[i],a[r]);
                i++;r--;
            }
            break;
        }
        counter++;
    }
}

int main(void)
{
     read(num);read(m);
     for(int i=1;i<=num;i++)a[i]=i;

     call(1,num,m);
     for(int i=1;i<=num;i++)printf("%d ",a[i]);

     return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef queue<ll> ql;
typedef set<ll> sl;
typedef vector<int> vi;
typedef queue<int> qi;
typedef set<int> si;

#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define fr(i, a, b) for(i=a; i<b; i++)
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define sortv(a) sort(a.begin(), a.end())
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define sqr(x) ((x) * (x))
#define sz(x) ((ll)x.size())

#define trace1(x)                           cerr << #x << ": " << x << endl;
#define trace2(x, y)                        cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)                     cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)                  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)               cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f)            cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

int i=0, j=0, k=0;

int main(){
    int n, m;
    cin >> n >> m;
    int left, right;
    if(n%2==0){
        int poss=pow(2, n/2);
        int array[n+1];
        for(i=1; i<n; i+=2){
            left=min(i, n-i+1);
            right=max(i, n-i+1);
            if(m>poss/2){
                array[left]=i+1;
                array[right]=i;
                m-=poss/2;
            }
            else{
                array[left]=i;
                array[right]=i+1;
            }
            poss/=2;
        }
        fr(i, 1, n+1){
            cout << array[i] << " ";
        }
        cout << endl;
        return 0;
    }
    int poss=pow(2, (n-2)/2)*3;
    int array[n+1];
    for(i=1; i<n-2; i+=2){
        left=min(i, n-i+1);
        right=max(i, n-i+1);
        if(m>poss/2){
            array[left]=i+1;
            array[right]=i;
            m-=poss/2;
        }
        else{
            array[left]=i;
            array[right]=i+1;
        }
        poss/=2;
    }
    if(m==1){
        array[n/2]=n-2;
        array[n/2+1]=n-1;
        array[n/2+2]=n;
    }
    if(m==2){
        array[n/2]=n-2;
        array[n/2+1]=n;
        array[n/2+2]=n-1;
    }
    if(m==3){
        array[n/2]=n-1;
        array[n/2+1]=n;
        array[n/2+2]=n-2;
    }
    fr(i, 1, n+1){
        cout << array[i] << " ";
    }
    cout << endl;
}

/*
 * File:   cf513B2.cpp
 * Author: Bslin
 * Mail:   Baoshenglin1994@gmail.com
 *
 * Created on Sun 08 Feb 2015 10:59:27 AM CST
 */

#include <cstdio>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
#endif
    int n, m, i;
    int ans[60];
    while(~scanf("%d%d", &n, &m)) {
        int l = 0, r = n - 1;
        for (i = n - 1; i > 0; i --) {
            if(m <= 1LL << (i - 1)) {
                ans[l ++] = n - i;
            } else {
                ans[r --] = n - i;
                m -= 1LL << (i - 1);
            }
        }
        ans[l ++] = n - i;
        for (i = 0; i < n; ++i) {
            printf("%d ", ans[i]);
        }
        puts("");
    }
    return 0;
}

//
//  cf513b2.cpp
//
//
//  Created by Apple on 2015/9/25.
//
//

#include <cstdio>
#include <algorithm>

using namespace std;

int func(int n, int *arr)
{
    int result = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i; j < n; ++j){
            result += *(min_element(arr + i, arr + j + 1));
        }
    }
    return result;
}

int main(){
    unsigned long long int n, m;
    while(~scanf("%I64d %I64d", &n, &m)){
        int arr[n];
        for(int i = 0; i < n; ++i){
            arr[i] = i + 1;
        }
        int max = 0;
        for(int i = 0; i < n; ++i){
            max += (i + 1) * (n - i);
        }
        int now = 0;
        bool flag = false;
        if(m < n * (n - 1)){
            do {
                if(max == func(n, arr)){
                    now++;
                    if(now == m){
                        flag = true;
                        break;
                    }
                }
            } while(next_permutation(arr, arr + n));
        }
        if(flag){
            for(int i = 0; i < n; ++i){
                printf("%I64d ", arr[i]);
            }
        } else {
            for(int i = n; i > 0; --i){
                printf("%I64d ", i);
            }
        }
        printf("\n");
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define LL      long long int
#define ULL     unsigned long long
#define pb      push_back
#define S       second
#define F       first
#define mp      make_pair
#define ios     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const LL  INF = 987698769876988899LL;
const int MOD = 1e9 + 7;
const int dx8[] = {1, 1, 0, -1, -1, -1, 0,1};
const int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx4[] = {1, -1, 0, 0};
const int dy4[] = {0, 0, 1, -1};

int n, m;
int ans[55];

int main()
{
    cin >> n >> m;
    int l = 0;
    int r = n - 1;
    LL p = (1LL << (n - 2));

    for(int i = 0; i < n; i++)
    {
        if(m > p)
        {
            ans[r--] = i + 1;
            m -= p;
        }
        else
        {
            ans[l++] = i + 1;
        }
        p /= 2;
    }

    for(int i = 0; i < n; i++)
        cout << ans[i] << " ";
}

#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <ctime>

#define sqr(a) (a) * (a)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define add insert
#define del erase
#define sz(a) (int)a.size()
#define forit(a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it ++)

using namespace std;

typedef long long LL;
typedef vector<int> Vi;
typedef set<int> Si;
typedef pair<int, int> Pii;

//const double EPS = 1e-9;
//const double PI = acos(-1.0);
//const int MAX_N = (int)1e5;
const int INF = (int)1e2;

int fp(vector<int> v)
{
    int res = 0;

    if (v.size())
    {
        int minVal = INF;
        int ind = -1;

        for (int i = 0; i < v.size(); i++)
            if (v[i] < minVal)
            {
                minVal = v[i];
                ind = i;
            }

        vector<int> l (ind), r (v.size() - ind - 1);

        if (ind) l.assign(v.begin(), v.begin() + ind);
        if (v.size() - ind - 1) r.assign(v.begin() + ind + 1, v.end());

        int cnt = (ind + 1) * ((int)v.size()  - ind);

        res += (fp(l) + fp(r) + minVal * cnt);
    }
    return res;
}

int main()
{
    int n, m, max_fp;

    cin >> n >> m;

    vector<int> v;
    for (int i = 0; i < n; i++)
        v.push_back(i + 1);

    max_fp = fp(v);

    while(m > 1)
    {
        bool swapped = false;
        for (int i = n - 1; i > 0 && !swapped; i--)
            for (int j = i - 1; j >= 0 && !swapped; j--)
            {
                vector<int> tmp = v;
                swap(tmp[i], tmp[j]);
                if (fp(tmp) == max_fp)
                {
                    swapped = true;
                    v = tmp;
                    m--;
                }
            }
    }

    for (int i = 0; i < v.size(); i++)
        cout << v[i] << " ";

    return 0;
}

// rc.cpp
//

#include <assert.h>
#include <time.h>
#include <math.h>
#include <string.h>

#include <iterator>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

#define PI 3.1415926535897932384626433832795
#define EPS 1E-8

uint64 f[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320 };

uint q[8];

bool v[8];

uint nxt(uint x)
{
	uint c = 0;
	for (uint i = 1; i < 8; ++i)
	{
		if (!v[i])
		{
			++c;
			if (c == x)
				return i;
		}
	}

	return 0;
}

int main(int argc, char* argv[])
{
	uint64 n, c;
	cin >> n >> c;

	uint ci = 0;
	if (c <= f[n - 1])
	{
		q[0] = 1;
		ci = 1;
	}
	else
	{
		q[n - 1] = 1;
		c -= f[n - 1];
	}

	uint cc = 2;

	for (uint i = 1; i < n; ++i)
	{
		uint g = 1;
		while (f[n - cc] * g < c)
			++g;

		c -= f[n - cc] * (g - 1);
		++cc;

		uint vi = nxt(g);
		v[vi] = true;
		q[ci] = vi + 1;
		++ci;
	}

	cout << q[0];
	for (uint i = 1; i < n; ++i)
		cout << ' ' << q[i];
	cout << endl;

	return 0;
}

/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<fstream>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<ctime>
#include<bitset>
#include<cmath>
#include<iomanip>
#include<set>
#define f cin
#define g cout
#include<queue>
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define mod 666013
#define N 100
#define SQR 350
#define inf 1<<30
#define div pula
using namespace std;

long long p,m;
int n,v[N];

int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m;
    m--;
    int st=1;
    int dr=n;
    p=(1<<(n-1));
    FOR(i,1,n)
    {
        if(p&m)
            v[dr--]=i;
        else
            v[st++]=i;
        p>>=1;
    }
    FOR(i,1,n)
    g<<v[i]<<" ";
    return 0;
}

//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii push_back
#define pb push_back
#define fff first
#define sss second

const int MN=100*100*100*10;

int n,m;
vector<int> p;

int pow(int k){
	int ret=1;
	for (int i=0;i<k;i++)
		ret*=2;
	return ret;
}

void f(int k,int r){
	if (k==1){
		p.pb(1);
		return;
	}
	if (r<=pow(k-2))
		f(k-1,r);
	else
		f(k-1,r-pow(k-2));
	for (int i=0;i<p.size();i++)
		p[i]++;
	p.pb(1);
	if (r>pow(k-2)){
		//cout<<" : | ";
		return;
	}
	for (int i=p.size()-1;i>0;i--){
		p[i]=p[i-1];
	}
	p[0]=1;
	return;
}

int main(){
	cin>>n>>m;
	f(n,m);
	for (int i=0;i<n;i++)
		cout<<p[i]<<" ";
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
using namespace std;

int n,m=0;
vector<int> p;
vector<bool> used;
string str;
void lex(int pos,int k)
{
    if (pos == n) {
        m++;
        if (m == k)
        {
            for (int i = 0; i < n; i++)
                cout << str[p[i]]<<" ";
            cout << endl;
        }
        return;
    }
    for (int i = 0; i<n; i++) {
        if (!used[i]) {
            used[i] = true;
            p[pos] = i;
            lex(pos + 1,k);

            p[pos] = 0;
            used[i] = false;
        }
    }
}
int main()
{
    int k;
    cin >>n>>k;
    for (long long i = 0; i < n; i++)
        str += to_string(i+1);
    p.resize(n);
    used.resize(n);
    lex(0,k);
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define rep(x, y, z) for(int x=y;x<z;x++)
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> P;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
const int maxn=1e6+7;
int n, m;
int a[maxn];
ll A[60];
bool f(){
	int ok=0;
	rep(i, 1, n+1){
		if(a[i] > a[i-1]){
			if(ok == 2) return false;
			ok = 1;
		}
		else if(a[i] < a[i-1]) {
			ok = 2;
		}
	}
	return true;
}
int main(){
#ifdef ac
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    cin>>n>>m;
	rep(i, 1, maxn) a[i]=i;
	A[0]=1;
	rep(i, 1, 52) A[i] = A[i-1] * 2;
	int p=1, q=n;
	ll t=0;
	rep(i, 1, n){
		if(m <= A[n-1-i]+t) {
			a[p++]=i;
			t=0;
		}
		else {
			a[q--]=i;
			t += A[n-1-i];
		}
		//m = abs(m - A[n-1-i]);
		//m /= 2;
	}
	a[p]=n;
	rep(i, 1, n+1) cout<<a[i]<<" ";
	cout<<endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int n, m;
int a[100];
int f[100000], maxf, curr;

int calc_f() {
    int f = 0;
    for (int i = 0; i < n; i++) {
        int m = a[i];
        for (int j = i; j < n; j++) {
            m = min(a[i], a[j]);
            f += m;
        }
    }
    return f;
}

int fuckt(int n) {
    int t = 1;
    for (int i = 1; i <= n; i++)
        t*=i;
    return t;
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        a[i] = i + 1;
    for (int i = 0; i < m - 1; i++)
        next_permutation(a, a + n);
    for (int j = 0; j < n; j++) {
        cout << a[j] << ' ';
    }
    /*int ans = -1;
    for (int i = 0; i < fuckt(n); i++) {
        f[i] = calc_f();
        if (maxf < f[i]) {
            maxf = f[i];
            curr = 0;
        }
        if (maxf == f[i]) {
            curr++;
            if (curr == m)
                ans = i;
        }
        next_permutation(a, a + n);
    }
    //next_permutation(a, a + n);
    for (int i = 0; i < fuckt(n); i++) {

        if (f[i] == maxf) {
            for (int j = 0; j < n; j++) {
                cout << a[j] << ' ';
            }
            cout << '\n';
        }
        next_permutation(a, a + n);
    }

*/

    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
long long get_fval(vector<int> a)
{
    int m=0, n =a.size();
    for(int i=0;i<n;i++)
    {
        m += ((n-i)*(i+1));
    }
    return m;
}

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> a;
    int i=0;
    long long mval = 0;
    for(int i=0;i<n;i++)
    {
        a.push_back(i+1);
        mval += ((n-i)*(i+1));
    }
    int mvali = 0;
    do
    {
        i++;
        mvali = get_fval(a);
        if(mval==mvali && i==m)
        {
            for(int i=0;i<n;i++)
            {
                cout<<a[i]<<" ";
            }
            cout<<endl;
            break;
        }
        else if(mval<mvali)
        {
            mval  =mvali;
            i = 0;
        }
    }
    while(next_permutation(a.begin(),a.end()));
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a[100];

int main()
{
    int n, m;
    cin >> n >> m;
    if (n == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    if (n == 2)
    {
        if (m == 1)
            cout << "1 2" << endl;
        else
            cout << "2 1" << endl;
        return 0;
    }
    int cnt = 1;
    for (int i = 1; i <= n; i++)
        cnt *= i;
    int k = n;
    int l = 0, r = n - 1;
    for (int i = 1; i <= n; i++)
    {
        if (m <= cnt / 2)
        {
            a[l++] = i;
        } else
        {
            a[r--] = i;
            m -= cnt / 2;
        }
        cnt /= k--;
    }
    for (int i = 0; i < n; i++)
        printf("%d%c", a[i], " \n"[i == n - 1]);
    return 0;
}

#include <iostream>
#include <cstdio>
#include <climits>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <ctime>
#define SET(p) memset(p,-1,sizeof(p))
#define CLR(p) memset(p,0,sizeof(p))
#define LL long long int
#define ULL unsigned long long int
#define pb push_back
#define cin(n) scanf("%d",&n)
using namespace std;
#define mp make_pair
#define ill long long

int main()
{
    int t,m,n,i,j,k,l;
    //cin(t);
    t=1;
    while(t--)
    {
        cin>>n>>m;
        int pos=n-m;
        if(n==2&&m==2)
        {
            cout<<"2 1"<<"\n";
            return 0;
        }
        if(m>=n)
        {
            m-=(n-1);
            for(i=1;i<=n-1;i++)
            {
                if(i==(n-m+1))
                    cout<<n<<" ";
                cout<<n-i<<" ";
            }
            if(m==1)
                cout<<n<<"\n";
            return 0;
        }
        for(i=1;i<=n-1;i++)
        {
            if(i==(n-m+1))
                cout<<n<<" ";
            cout<<i<<" ";
        }
        if(m==1)
            cout<<n<<"\n";

    }

    //cout<<ans<<"\n";

    return 0;
}

#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0;i<(int)(n);++(i))
#define REPIT(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define PB push_back
#define FT first
#define SD second
#define ZERO(x) memset(x,0,sizeof(x))
#define NEG(x) memset(x,-1,sizeof(x))
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define OIII(x,y,z) printf("%d %d %d\n",(x),(y),(z))
#define OII(x,y) printf("%d %d\n",(x),(y))
#define OI(x) printf("%d\n",(x))
#define OL(x) cout<<(x)<<endl
#define OLL(x,y) cout<<(x)<<" "<<(y)<<endl
#define OLLL(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define RS(s) scanf("%s",(s))
#define MP(x,y) make_pair((x),(y))
#define FIN(f) freopen(f,"r",stdin)
#define FOUT(f) freopen(f,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<int,int> PII;
const int MOD = 1e9+7;
const int maxn = 1501;
const int INF = 1<<30;
int n,m;
int main(int argc, char const *argv[])
{
    FIN("in.txt");
    RII(n,m);
    vector<int> l,r;
    for(int p=0;p<n;p++) {
        if(m>=1<<(n-p-1)) {
            r.PB(p+1);
            m-=1<<(n-p-1);
        } else {
            l.PB(p+1);
        }
    }
    for(int i=0;i<r.size();++i)l.PB(r[i]);
    for(int i=0;i<n;++i)printf("%d ",l[i]);
}

#include <bits/stdc++.h>

typedef long long int ll;
using namespace std;

int fmin(int arr[], int s, int e){
	int min = 999999999;
	for(int i=s; i<=e; ++i){
		if(min>arr[i]) min=arr[i];
	}
	return min;
}

int fmax(int arr[], int n){
	int max=0;
	for(int i=0; i<n; ++i){
		if(max<arr[i]) max=arr[i];
	}
	return max;
}

int fact(int n){
	if(n==0 || n==1) return 1;
	return n*fact(n-1);
}

int main()
{
    int n,m, in=0, c=0;
    cin>>n>>m;
    int arr[n+1], A[50000], ar[n+1];
    for(int i=1; i<=n; ++i){
		arr[i-1] = i;
		ar[i-1] = i;
	}
    while(true){
		int f=0;
		for(int i=0; i<n; ++i){
			for(int j=i; j<n; ++j){
				f += fmin(arr, i, j);
			}
		}
		A[in] = f;
		if(arr[0]==n && arr[n-1]==1) break;
		next_permutation(arr, arr+n);
		in++;
	}

	int maxi = fmax(A, fact(n));
	for(int i=0; i<fact(n); ++i){
		if(A[i] == maxi){
			c++;
		}
		if(c==m){
			for(int k=0; k<n; ++k){
				cout<<ar[k]<<" ";
			}
			break;
		}
		next_permutation(ar,ar+n);
	}
}

#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif

typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;

const int INF = (1LL << 31) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int MOD = (int)(1e9) + 7;

const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;

lld N, M, j;

void solve(int i, int j) {
    if(i <= 1) {
        if(j == 1)
            printf("%d %d %d ", N - 2, N - 1, N);
        else if(j == 2)
            printf("%d %d %d ", N - 2, N, N - 1);
        else if(j == 3)
            printf("%d %d %d ", N - 1, N - 2, N);
        else
            printf("%d %d %d ", N, N - 1, N - 2);
        return;
    }

    if(j & (1LL << i)) {
        solve(i - 1, j - (1LL << i));
        printf("%d ", N - i - 1);
    } else {
        printf("%d ", N - i - 1);
        solve(i - 1, j - (1LL << i));
    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen(inputFile.c_str(), "r", stdin);
    freopen(outputFile.c_str(), "w", stdout);
#endif

    scanf("%lld%lld", &N, &M);

    if(N >= 3)
        solve(N - 2, M);
    else {
        if(N == 1)
            printf("1 ");
        else if(N == 2 && M == 1)
            printf("1 2 ");
        else printf("2 1 ");
    }

    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <random>
#include <set>

using namespace std;

// mt19937 rng(5);
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define fo(i, n) for (int i = 0; i < n; ++i)
#define fo1(i, n) for (int i = 1; i <= n; ++i)
#define foback(i, n) for (int i = n - 1; i >= 0; --i)

typedef long long ll;

void fastio()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void one();

int main()
{
    fastio();

    int t = 1;
    // cin >> t;
    fo(i, t)
    {
        one();
    }
    return 0;
}

void one()
{
    ll n;
    cin >> n;

    ll m;
    cin >> m;

    vector<int> ans(n);
    int l = 0;
    int r = n - 1;

    ll pos = 1;
    fo1(i, n)
    {
        ll cur = 1LL << (n - pos - 1);
        if (m <= cur)
        {
            ans[l++] = i;
            pos++;
        }
        else
        {
            ans[r--] = i;

            pos++;
            m = cur - m;
        }
    }

    fo(i, n) cout << ans[i] << " ";
    cout << endl;
}

/*
Author:Chieh
Because of You
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#define LL long long
using namespace std;
struct he
{
    int sum,pl;
};
vector<he> V;
vector<int> V1;
int n,m;
int q;
int  used[100];
int bi[100];
bool cmp(he a,he b)
{
    if(a.sum!=b.sum)return a.sum>b.sum;
    return a.pl<b.pl;
}
void DFS(int now)
{
    //cout<<now<<endl;
    if(now==n+1)
    {
        q++;
        he a;
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int MIN=bi[i];
            for(int j=i; j<=n; j++)
            {
                MIN=min(MIN,bi[j]);
                sum+=MIN;
            }

        }
        a.sum=sum;
        a.pl=q;
        V.push_back(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(used[i]!=0)continue;
        used[i]=now;
        bi[now]=i;
        DFS(now+1);
        used[i]=0;

    }
}
bool DFS1(int now)
{
    //cout<<now<<endl;
    if(now==n+1)
    {
        q++;

        if(q==m)
        {
            return 1;
        }
        return 0;
    }
    for(int i=1; i<=n; i++)
    {
        if(used[i])continue;
        used[i]=1;
        bool z=DFS1(now+1);
        used[i]=0;
        if(z)
        {
            V1.push_back(i);
            return 1;
        }

    }
    return 0;
}
void init()
{
}
vector<int> l,r;
void play()
{
    V1.clear();
    m--;
    l.clear();
    r.clear();
    while(m>0)
    {
        if(m%2==0)
        {
            V1.push_back(0);
        }
        else{
            V1.push_back(1);
        }
        m/=2;
    }
    int st=n-1;
    for(int i=0;i<V1.size();i++){
        if(V1[i]==1){
            r.push_back(st);
        }
        else {
            l.push_back(st);
        }
        st--;
    }
    for(int i=1;i<=st;i++){
        l.push_back(i);
    }
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    for(int i=0;i<l.size();i++){
        printf("%d ",l[i]);
    }
    printf("%d ",n);
    for(int i=r.size()-1;i>=0;i--){
        printf("%d ",r[i]);
    }
    printf("\n");
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        init();
        play();
    }
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define ll long long
#include<vector>
#include<string>
#include<queue>
#define N 1000005
#define ll long long
using namespace std;
int a[100];

vector<int> perm(ll n, int add, ll m)
{
    ll len = 1<<(n-1);
    if(n==1)
    {
        vector<int> ret;
        ret.push_back(1+add);
        return ret;
    }

    vector<int> ret;
    if(m<=len/2)
    {
            ret.push_back(1+add);
            vector<int> tm  = perm(n-1,add+1,m);

            for(int i=0;i<tm.size();i++)
            ret.push_back(tm[i]);
    }
    else
    {
        m  -=len/2;
        m = len/2-m+1;

        ret =perm(n-1,add+1,m);
        reverse(ret.begin(),ret.end());
        ret.push_back(1+add);
    }
    return ret;
}

void print(vector<int>& v)
{
    for(int i=0;i<v.size();i++)
    cout<<v[i]<<" ";
    cout<<endl;
}

int p(int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int tm=99999999;
        for(int j=i;j<n;j++)
        {
            tm = min(tm,a[j]);
            ans+=tm;
        }
    }
    return ans;
}

int main()
{

  //  freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
  //  int a[1000];
    for(int i=1;i<=n;i++)
    a[i-1]=i;
/*
    int Max=0;
    do
    {
        Max=max(Max,p(n));
    }while(next_permutation(a,a+n));

    for(int i=1;i<=n;i++)
    a[i-1]=i;
    int cnt=0;
    do
    {
        if(p(n)==Max) cnt++;
       if(cnt==m)
        {
            for(int i=0;i<n;i++)
            cout<<a[i]<<" ";
            cout<<endl;
            break;
         //   return 0;
        }
    }while(next_permutation(a,a+n));*/
    vector<int> ret = perm(n,0,m);

    print(ret);
    return 0;
}

#if 1
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>

using namespace std;

const long long test = 9e18;

typedef unsigned long long ll;
typedef long double ld;
typedef double dd;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define X first
#define Y second
#define file "file"
#define mp make_pair
#define pb push_back

vector< vector<int> > g;
vector<int> dist, norm;
vector<int> used;

int main()
{
    //cout << test << endl;
  //  freopen(file".in", "r", stdin);
 //   freopen(file".out", "w", stdout);
#ifdef _DEBUG
#endif
    int n, k;
    cin>>n >> k;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    vector<int> otv(n);
    int sum=0;
    int p = 0;
    do
    {
        int sum2=0;
        for(int i=0;i<n;i++)
        {
            int mi = a[i];
            for(int j=0;j<n;j++)
            {
                mi = min(mi, a[j]);
                sum2+=a[j];
            }
        }
        if(sum2 == sum)
            p++;
        if(p == k)
            for(int i=0;i<n;i++)
            {
                otv[i] = a[i];
            }
        if(sum2 > sum)
        {
            p = 1;
            sum = sum2;
        }
    }while(next_permutation(a.begin(),a.end()));
    for(int i=0;i<n;i++)
    {
        cout<<otv[i] << ' ';
    }
    return 0;
}
#endif

#include <iostream>
#include <vector>
#include <deque>
#include <cassert>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdint>
#include <limits>

using namespace std;

int foo(const vector<int>& perm)
{
    int res = 0;
    for (int i = 0; i < perm.size(); ++i)
        for (int j = i; j < perm.size(); ++j)
            res += *min_element(perm.begin() + i, perm.begin() + j + 1);

    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    int64_t n, m;
    cin >> n >> m;
    m--;

    int64_t totalAns = 1 << (n - 1);

    vector<int> ans(n);

    auto l = ans.begin();
    auto r = ans.end() - 1;

    int filled = 0;
    while (filled < n)
    {
        if (m < totalAns / 2)
        {
            filled++;
            totalAns /= 2;
            *l = filled;
            l++;
        }
        else
        {
            filled++;
            totalAns /= 2;
            m -= totalAns;
            *r = filled;
            r--;
        }
    }

    for (auto elt : ans)
        cout << elt << ' ';

    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>

#define oo 1e9
#define pi 3.1415926536
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define sortam(x,comp) sort(all(x),comp)
#define sortd(x) sort(x.rbegin(),x.rend())
#define pb push_back
#define mp make_pair
#define sf(x) scanf("%d", &x);
#define sfll(x) scanf("%I64d", &x);
#define pr(x) printf("%d ", x);

typedef long long ll;
using namespace std;

int main() {
    int n, m;
    while(cin >> n >> m) {
        if(n == 1) { cout << 1 << endl; continue; }
        vector<int>t;
        for(int i = 1; i <= n; i++) t.push_back(i);
        vector<vector<int> >res;
        res.push_back(t);
        int get = n - 1;
        while(res[res.size() - 1][0] != n) {
            int sz = res.size();
            for(int i = 0; i < sz && res.size()<m; i++) {
                t = res[i];
                t.erase(t.begin() + get - 1);
                t.push_back(get);
                res.push_back(t);
            }
            if(res.size() >= m) break;
            get--;
        }
        for(int i = 0; i < res[m-1].size(); i++) pr(res[m-1][i]);
        printf("\n");

    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <string>
#include <sstream>
#include <vector>
#include <ctime>
#include <cstring>
#include <fstream>
#include <functional>

#define ll long long
#define ld long double
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi >
#define pii pair<int,int>
#define pll pair<ll,ll>
#define forr(i, x, n) for(int i = (x);i < (n);i++)
#define forn(i, n) forr(i, 0, (n))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define sqrt(x) (pow((double)x, 0.5))
#define sqr(x) ((x) * (x))
#define mp make_pair
#define TASKNAME ""

#ifdef _DEBUG
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) ((void)42)
#endif

const int inf = 1e9;
const ll infll = 1e18;
const int mod = 1e9 + 7;
const ld eps = 1e-9;

using namespace std;

int factorial(int x) {
	return (x == 1 ? x : x * factorial(x - 1));
}

void solve(){
	int n, m;
	cin >> n >> m;
	vi p(n);
	forn(i, n)
		p[i] = i + 1;
	int max = 0;
	int c = 0;
	for (int i = 0; i < factorial(n); i++){
		int sum = 0;
		forn(j, n){
			int cmin = inf;
			forr(l, j + 1, n + 1){
				forr(k, j, l)
					cmin = min(cmin, p[k]);
				sum += cmin;
			}
		}
		if (sum > max){
			max = sum;
			c = 1;
		}
		if (sum == max)
			c++;
		if (c == m){
			forn(j, n)
				cout << p[j] << " ";
			break;
		}
		next_permutation(p.begin(), p.end());
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

	return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<stdlib.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
set<string> mySet;
void permutations(string s)
{
    string t = s;
    mySet.insert(s);
    for (int i = 0; i < s.size(); i++)
    {
        for (int j = 0; j < s.size(); j++)
        {
            //cout << s << endl;
            swap(s[i], s[j]);
            mySet.insert(s);
        }
    }
}
int main()
{
    int n, m;
    cin >> n >> m;
    m--;
    char index = '1';
    string s = "";
    for (int i = 0; i < n; i++)
    {
        s += index;
        index++;
    }
    //cout << s << endl;
    permutations(s);
    set<string>::iterator myIt=mySet.begin();
    while (m>0)
    {
        myIt++;
        m--;
    }
    for (int i = 0; i < (*myIt).size(); i++)
    {
        cout << (*myIt)[i];
        if (i < (*myIt).size() - 1)
            cout << " ";
    }
    //system("pause");
    return 0;
}

#include <deque>
#include <iostream>

#define int long long

using namespace std;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  --m;
  int a[n];
  int i = n - 2;
  int l = 0, r = n - 1, cur = 1;
  while (l < r) {
    if (m & (1 << i--)) {
      a[r--] = cur++;
    } else {
      a[l++] = cur++;
    }
  }
  a[l] = cur;
  for (i = 0; i < n; ++i) {
    cout << a[i] << ' ';
  }
  return 0;
}