# coding:utf-8 import sys # from itertools import product ume = [0, 0, 0, 1, 3, 6, 11, 21, 42, 85, 171, 342, 683, 1365, 2730, 5461, 10923, 21846, 43691, 87381, 174762, 349525, 699051, 1398102, 2796203, 5592405, 10000001] def popcount(x): return bin(x).count("1") # if N in ume: # print(ume.index(N)) # sys.exit() # else: def solve(): N = int(input()) count = 0 for u in range(len(ume)): if N==ume[u]: i = u+1 count = ume[u-1] break elif Ni-1: break a = '0'*(i-1-len(a))+a n = a.replace('0', '3').replace('1', '5') x = ''.join(n) x = int(x) # print(a, a[-1]) if popcount(j)%3==0 and popcount(j)>=3 and a[-1]=='1': # if x%15==0: # print(x,str(x).count('5')) count += 1 # print(x, count) if count==N: print(x) sys.exit() solve()