N = int(input()) def sfb(n): xs = str(n) for x in xs: if x != '3' and x != '5': return False return True def solve(): s = 0 c = 0 n = 37 while True: s = n * 15 if sfb(s): c = c + 1 if c == N: return s n = n + 10 print(solve())