# coding:utf-8 import sys ume_i=[0, 19, 20, 20, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25] ume_j=[0,75711, 151419, 751427, 302841, 902867, 1502853, 5699, 605701, 1205719, 1805703, 2405735, 3005701, 3605711, 11401, 611385, 1211401, 1811391, 2411421, 3011415, 3611383, 4211407, 4811419, 5411397, 6011395, 6611385, 7211393, 7811395, 22793, 622799, 1222795, 1822785, 2422789, 3022785, 3622775, 4222781, 4822807, 5422785, 6022785, 6622785, 7222771, 7822783, 8422785, 9022791, 9622769, 10222757, 10822781, 11422765, 12022781, 12622791, 13222757, 13822781, 14422783, 15022781, 15622793, 16222799, 45571, 645581, 1245591, 1845571, 2445581, 3045545, 3645561, 4245563, 4845567, 5445567, 6045557, 6645539, 7245557, 7845545, 8445561, 9045557, 9645563, 10245539, 10845557, 11445545, 12045553, 12645561, 13245557, 13845559, 14445575, 15045563, 15645565, 16245553, 16845567, 17445591, 18045541, 18645545, 19245537, 19845569, 20445563, 21045561, 21645557, 22245545, 22845567, 23445569, 24045561, 24645569, 25245579, 25845563, 26445559] #def popcount(x): # return bin(x).count("1") def popcount(n): n = (n & 0x5555555555555555) + ((n & 0xAAAAAAAAAAAAAAAA) >> 1) n = (n & 0x3333333333333333) + ((n & 0xCCCCCCCCCCCCCCCC) >> 2) n = (n & 0x0F0F0F0F0F0F0F0F) + ((n & 0xF0F0F0F0F0F0F0F0) >> 4) n = (n & 0x00FF00FF00FF00FF) + ((n & 0xFF00FF00FF00FF00) >> 8) n = (n & 0x0000FFFF0000FFFF) + ((n & 0xFFFF0000FFFF0000) >> 16) n = (n & 0x00000000FFFFFFFF) + ((n & 0xFFFFFFFF00000000) >> 32) return n def solve(): N = int(input()) count = 0 # 100000毎にume # ume_i = [] # ume_j = [] # c = 1000000 p = int(N/100000) start_i = ume_i[p] start_j = ume_j[p] if p!=0: count = p*100000-1 x = 0 for i in range(start_i,26): for j in range(start_j,10000000000000): a = bin(j)[2:] if len(a)>i: # print(i,j,a) start_j = 0 break # print(a) if popcount(j)%3==0 and popcount(j)>=3 and a[-1]=='1': count += 1 # ==== # if count == c: # ume_i.append(i) # ume_j.append(j) # c += 1000000 # ==== if count==N: a = '0'*(i-len(a))+a n = a.replace('0', '3').replace('1', '5') x = ''.join(n) x = int(x) print(x) sys.exit() solve()