#include <bits/stdc++.h>

using namespace std;
const int N = 30;
int g[N];
bool col[N], dg[N], udg[N];

int b;
int n = 8;
int cnt;
vector<string> res;

void dfs(int u){
	if (u == n){
		string str;
		for (int i=0; i<n; i++){
			str.push_back(g[i] + '0');
		}
		res.push_back(str);
		cnt++;
		return;
	}
	
	int x = u;
	for (int y=0; y<n; y++){
		if (!col[y] && !dg[x-y+n] && !udg[y+x]) {
			col[y] = dg[x-y+n] = udg[y+x] = true;
			g[x] = y+1;
			dfs(u+1);
			g[x] = 0;
			col[y] = dg[x-y+n] = udg[y+x] = false;		
		}
	}
}

int main() {

	dfs(0);
	
	int b;
	// sort(res.begin(), res.end());
	while (cin >> b){
		cout << res[b-1] << endl;
	}
	
	return 0;
}