k = int(eval(input()))

ans = []





def dfs(x):

    if x > 10**10:

        return 0

    else:

        ans.append(x)

        y = x % 10

        for i in range(10):

            if abs(y-i) <= 1:

                dfs(10*x+i)

                

for i in range(1, 10):

    dfs(i)

ans.sort()

print((ans[k-1]))
k = int(eval(input()))

ans = []





def dfs(x):

    if x > 3234566667:

        return 0

    else:

        ans.append(x)

        y = x % 10

        for i in range(10):

            if abs(y-i) <= 1:

                dfs(10*x+i)

    



for i in range(1, 10):

    dfs(i)

    

ans.sort()

print((ans[k-1]))
k = int(eval(input()))
ans = []


def dfs(x):
    if x > 10**10:
        return 0
    else:
        ans.append(x)
        y = x % 10
        for i in range(10):
            if abs(y - i) <= 1:
                dfs(10 * x + i)


for i in range(1, 10):
    dfs(i)
ans.sort()
print((ans[k - 1]))

k = int(eval(input()))
ans = []


def dfs(x):
    if x > 3234566667:
        return 0
    else:
        ans.append(x)
        y = x % 10
        for i in range(10):
            if abs(y - i) <= 1:
                dfs(10 * x + i)


for i in range(1, 10):
    dfs(i)
ans.sort()
print((ans[k - 1]))

-    if x > 10**10: +    if x > 3234566667: