k=int(eval(input()))

ans=[i for i in range(1,10)]

def dfs(x):

    if x>=3234566667:

        return

    for i in range(max(0,x%10-1),min(10,x%10+2)):

        ans.append(10*x+i)

        dfs(10*x+i)

for i in range(1,10):

    dfs(i)

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

a=[]

def dfs(v):

    if v>3234566667:

        return

    a.append(v)

    for i in range(max(0,v%10-1),min(v%10+2,10)):

        dfs(10*v+i)

for i in range(1,10):

    dfs(i)

a.sort()

print((a[k-1]))
k = int(eval(input()))
ans = [i for i in range(1, 10)]


def dfs(x):
    if x >= 3234566667:
        return
    for i in range(max(0, x % 10 - 1), min(10, x % 10 + 2)):
        ans.append(10 * x + i)
        dfs(10 * x + i)


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

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


def dfs(v):
    if v > 3234566667:
        return
    a.append(v)
    for i in range(max(0, v % 10 - 1), min(v % 10 + 2, 10)):
        dfs(10 * v + i)


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

-ans = [i for i in range(1, 10)] +a = [] -def dfs(x): -    if x >= 3234566667: +def dfs(v): +    if v > 3234566667: -    for i in range(max(0, x % 10 - 1), min(10, x % 10 + 2)): -        ans.append(10 * x + i) -        dfs(10 * x + i) +    a.append(v) +    for i in range(max(0, v % 10 - 1), min(v % 10 + 2, 10)): +        dfs(10 * v + i) -print((sorted(ans)[k - 1])) +a.sort() +print((a[k - 1]))