#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++) #define EPS (1e-14) using namespace std; typedef long long ll; typedef pair PII; typedef pair PLL; typedef complex Complex; typedef vector< vector > Mat; ll N; string ans; ll C[1005][1005]; void combination(int size) { for (int i = 0; i < size; i++) C[i][0] = 1LL; for (int i = 1; i < size; i++) { for (int j = 1; j <= i; j++) { C[i][j] = (C[i-1][j-1] + C[i-1][j]); } } } ll count(int d) { ll res = 0; for (int i = 0; i < d; i++) { if ((i + 1) % 3 != 0) continue; res += C[d - 1][i]; } return res; } string calc(int d, int g) { string res = ""; int mask = 0; for (; mask < (1 << d); mask++) { int bitcount = 0; rep(i, d) if (mask & (1 << i)) bitcount++; if ((mask & 1) == 1 && bitcount % 3 == 0) g--; if (g == 0) break; } for (int i = d - 1; i >= 0; i--) { if (mask & (1 << i)) res += '5'; else res += '3'; } return res; } void solve() { combination(35); ll cur = 0; for (int d = 1; d < 30; d++) { ll num = count(d); if (num + cur >= N) { ans = calc(d, N - cur); break; } cur += num; } cout << ans << endl; } int main() { cin >> N; solve(); return 0; }