#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; vector> combinations(int n){ auto res = vector>(n + 1, vector(n + 1)); for(int i=0; i<=n; ++i)res[i][0] = 1; for(int i = 1; i <= n; ++i) for(int j = 1; j <= i; ++j) res[i][j] = res[i - 1][j - 1] + res[i - 1][j]; return res; } int bitcnt(int n){ int res = 0; while(n){ if(n&1) ++res; n>>=1; } return res; } int main(){ auto C = combinations(25); int N; while(cin >> N){ for(int d = 3; d <= 25; ++d){ ll tot = 0; for(int i = 0; i <= d - 1; ++i){ if((i + 1) % 3 == 0) tot += C[d - 1][i]; } if(N > tot)N -= tot; else{ for(int S = 1; N > 0 && S < (1 << d); S += 2){ if(bitcnt(S) % 3 == 0)N--; if(N == 0){ string ans; rep(i, d)ans += ((S >> (d - 1 - i) & 1) ? '5' : '3'); cout << ans << endl; } } break; } } } }