import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long[][] nCk = new long[26][26]; nCk[0][0] = 1; for (int i = 1; i <= 25; ++i) { for (int j = 0; j <= i; ++j) { nCk[i][j] = (j > 0 ? nCk[i - 1][j - 1] : 0) + (i - 1 >= j ? nCk[i - 1][j] : 0); } } long[] count = new long[26];// count[i]:i桁の時の組み合わせの数 for (int i = 1; i < count.length; ++i) { count[i] = count[i - 1]; for (int j = 3; j <= i; j += 3) { count[i] += nCk[i - 1][j - 1]; } } int N = sc.nextInt(); int digit = 0; while (count[digit] < N) ++digit; long cnt = N - count[digit - 1]; for (int i = 1; i < (1 << digit); i += 2) { int c5 = Integer.bitCount(i); if (c5 % 3 == 0) { --cnt; } if (cnt == 0) { for (int j = digit - 1; j >= 0; --j) { if (((1 << j) & i) > 0) { System.out.print(5); } else { System.out.print(3); } } System.out.println(); return; } } tr(count[digit]); tr(count); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }