#include<iostream> #include<vector> using namespace std; const int N = 20; int b; bool col[N],dg[N],udg[N]; vector<int>res; void dfs(int n,int u,int s) { if(u==n) { res.push_back(s); return; } for(int i=0; i<n; i++) { if(!col[i] && !dg[u+i] && !udg[n-i+u]) { col[i] = dg[u+i] = udg[n-i+u] = true; dfs(n,u+1,i+1+10*s); col[i] = dg[u+i] = udg[n-i+u] = false; } } } int main() { // freopen("input.txt","r",stdin); dfs(8,0,0); while(~scanf("%d",&b)) { printf("%d\n",res[b-1]); } return 0; }