def f(x): start = 0 for i in range(30): if x & (1 << i) != 0: start = i res = "" for i in range(start - 1, -1, -1): if x & (1 << i) != 0: res += "5" else: res += "3" return res n = int(input()) xs = [] for d in range(3, 26): x = 0 for _ in range(1 << d): x += 1 if x & 1 != 0 and x.bit_count() % 3 == 0: xs.append((1 << d) | x) ans = f(xs[n - 1]) print(ans)