k=int(eval(input()))

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

d=9

while d<k:

    ans.append([])

    for i in ans[-2]:

        x=str(i)

        y=int(x[0])

        if y==1:

            ans[-1].append(str(y)+x)

            ans[-1].append(str(y+1)+x)

        elif 2<=y<=8:

            ans[-1].append(str(y-1)+x)

            ans[-1].append(str(y)+x)

            ans[-1].append(str(y+1)+x)

        else:

            ans[-1].append(str(y-1)+x)

            ans[-1].append(str(y)+x)

        z=int(x[-1])

        if z==0:

            ans[-1].append(x+str(z))

            ans[-1].append(x+str(z+1))

        elif 1<=z<=8:

            ans[-1].append(x+str(z-1))

            ans[-1].append(x+str(z))

            ans[-1].append(x+str(z+1))

        else:

            ans[-1].append(x+str(z-1))

            ans[-1].append(x+str(z))

    ans[-1]=list(set(ans[-1]))

    d+=len(ans[-1])

l=len(ans[-1])

v=sorted([int(i) for i in ans[-1]])



print((v[k-(d-l)-1]))
k=int(eval(input()))

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

d=9

while d<k:

    ans.append([])

    for i in ans[-2]:

        x=str(i)

        z=int(x[-1])

        if z==0:

            ans[-1].append(x+str(z))

            ans[-1].append(x+str(z+1))

        elif 1<=z<=8:

            ans[-1].append(x+str(z-1))

            ans[-1].append(x+str(z))

            ans[-1].append(x+str(z+1))

        else:

            ans[-1].append(x+str(z-1))

            ans[-1].append(x+str(z))

    d+=len(ans[-1])

l=len(ans[-1])

v=sorted([int(i) for i in ans[-1]])



print((v[k-(d-l)-1]))
k = int(eval(input()))
ans = [[i for i in range(1, 10)]]
d = 9
while d < k:
    ans.append([])
    for i in ans[-2]:
        x = str(i)
        y = int(x[0])
        if y == 1:
            ans[-1].append(str(y) + x)
            ans[-1].append(str(y + 1) + x)
        elif 2 <= y <= 8:
            ans[-1].append(str(y - 1) + x)
            ans[-1].append(str(y) + x)
            ans[-1].append(str(y + 1) + x)
        else:
            ans[-1].append(str(y - 1) + x)
            ans[-1].append(str(y) + x)
        z = int(x[-1])
        if z == 0:
            ans[-1].append(x + str(z))
            ans[-1].append(x + str(z + 1))
        elif 1 <= z <= 8:
            ans[-1].append(x + str(z - 1))
            ans[-1].append(x + str(z))
            ans[-1].append(x + str(z + 1))
        else:
            ans[-1].append(x + str(z - 1))
            ans[-1].append(x + str(z))
    ans[-1] = list(set(ans[-1]))
    d += len(ans[-1])
l = len(ans[-1])
v = sorted([int(i) for i in ans[-1]])
print((v[k - (d - l) - 1]))

k = int(eval(input()))
ans = [[i for i in range(1, 10)]]
d = 9
while d < k:
    ans.append([])
    for i in ans[-2]:
        x = str(i)
        z = int(x[-1])
        if z == 0:
            ans[-1].append(x + str(z))
            ans[-1].append(x + str(z + 1))
        elif 1 <= z <= 8:
            ans[-1].append(x + str(z - 1))
            ans[-1].append(x + str(z))
            ans[-1].append(x + str(z + 1))
        else:
            ans[-1].append(x + str(z - 1))
            ans[-1].append(x + str(z))
    d += len(ans[-1])
l = len(ans[-1])
v = sorted([int(i) for i in ans[-1]])
print((v[k - (d - l) - 1]))

-        y = int(x[0]) -        if y == 1: -            ans[-1].append(str(y) + x) -            ans[-1].append(str(y + 1) + x) -        elif 2 <= y <= 8: -            ans[-1].append(str(y - 1) + x) -            ans[-1].append(str(y) + x) -            ans[-1].append(str(y + 1) + x) -        else: -            ans[-1].append(str(y - 1) + x) -            ans[-1].append(str(y) + x) -    ans[-1] = list(set(ans[-1]))