import java.util.*; import java.io.*; public class Main { static long[][] comb = new long[200][200]; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextInt() - 1; for (int i = 0; i < 200; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) { comb[i][j] = 1; } else { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } } } int count = 2; while (true) { long sum = getSum(count); if (n <= sum) { break; } n -= sum; count++; } System.out.println(getString(count, n + 1) + "5"); } static long getSum(int count) { long sum = 0; for (int i = 0; i * 3 + 2 <= count; i++) { sum += getSum(count, i * 3 + 2); } return sum; } static long getSum(int all, int part) { return comb[all][part]; } static String getString(int count, long size) { int mask = 0; for (int i = 0; i < size; i++) { mask++; while (getPop(mask) % 3 < 2) { mask++; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { if (mask % 2 == 0) { sb.append("3"); } else { sb.append("5"); } mask >>= 1; } return sb.reverse().toString(); } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x /= 2; } return pop; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }