from itertools import permutations N = int(input()) L = [] for a, b, c, d, e, f, g in permutations(range(10), 7): if 100*a+10*b+c + 100*d+10*e+f == 1000+100*g+10*c+b \ and [1] not in [a, b, c, d, e, f] \ and len(set([a, b, c, d, e, f])) == 6: L += [1000+100*g+10*c+b] break for a, b, c, d, e, f, g, h, i in permutations(range(10), 9): if 1000*a+100*a+10*b+c + 1000*d+100*e+10*f+g == 10000+1000*h+100*b+10*c+i \ and [1] not in [a, b, c, d, e, f, g, h, i] \ and len(set([a, b, c, d, e, f, g, h, i])) == 9: L += [10000+1000*h+100*b+10*c+i] break L += [841341] print(L[N-1])