import sys from itertools import product N = int(input()) ans = [] count = 0 for i in range(22): for n in product('35', repeat=i+1): x = ''.join(n) x = int(x) if x%15==0: count += 1 # ans.append(x) if count==N: print(x) sys.exit()