#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; // constexpr int mod = 1000000007; constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; auto check = [](const string& s, const string& t){ if(s.length() != t.length()) return s.length() < t.length(); return s < t; }; priority_queue, decltype(check)> que(check); for(int L = 3; L <= 25; ++L){ for(int i = 3; i <= L; i += 3){ vector perm(L - 1, 1); for(int j = 0; j < L - 1 - (i - 1); ++j) perm[j] = 0; do { string s = ""; for(int j = 0; j < L - 1; ++j){ s += perm[j] == 0 ? '3' : '5'; } s += '5'; que.emplace(s); if(que.size() > N) que.pop(); } while(next_permutation(begin(perm), end(perm))); } if(que.size() == N) break; } cout << que.top() << endl; return 0; }