import java.util.*; public class Main { static final int MAX = 26; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] comb = new int[MAX][MAX]; int max = 0; for (int i = 0; i < MAX; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || i == j) { comb[i][j] = 1; } else { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } } } int[] counts = new int[MAX]; for (int i = 2; i < MAX; i++) { for (int j = 2; j <= i; j += 3) { counts[i] += comb[i][j]; } } int idx = 0; for (int i = 2; i < MAX; i++) { if (n > counts[i]) { n -= counts[i]; } else { idx = i; break; } } for (int i = 0; i < (1 << idx); i++) { if (getCount(i) % 3 == 2) { n--; } if (n == 0) { System.out.println(getNum(i, idx)); return; } } } static String getNum(int x, int length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { if (x % 2 == 0) { sb.append("3"); } else { sb.append("5"); } x /= 2; } return sb.reverse() + "5"; } static int getCount(int x) { int count = 0; while (x > 0) { count += x % 2; x /= 2; } return count; } }