from itertools import permutations N = int(input()) L = [] for A, B, C, D, E, F, G in permutations(range(10), 7): if A*D*B == 0: continue if B != 1: continue ABC = 100*A + 10*B + C DEF = 100*D + 10*E + F BGCB = 1000*B + 100*G + 10*C + B if ABC + DEF == BGCB: L += [BGCB] break for A, B, C, D, E, F, G, H, I, J in permutations(range(10), 10): if A*D*H == 0: continue if H != 1: continue AABC = 1000*A + 100*A + 10*B + C DEFG = 1000*D + 100*E + 10*F + G HIBCJ = 10000*H + 1000*I + 100*B + 10*C + J if AABC + DEFG == HIBCJ: L += [HIBCJ] break L += [841341] print(L[N-1])