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])

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

        if z<=8:

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

        if z>=1:

            ans[-1].append(x+str(z-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])

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

        if z<=8:

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

        if z>=1:

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

    d+=len(ans[-1])

ans[-1].sort()

print((ans[-1][k-d-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])
        ans[-1].append(x + str(z))
        if z <= 8:
            ans[-1].append(x + str(z + 1))
        if z >= 1:
            ans[-1].append(x + str(z - 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])
        ans[-1].append(x + str(z))
        if z <= 8:
            ans[-1].append(x + str(z + 1))
        if z >= 1:
            ans[-1].append(x + str(z - 1))
    d += len(ans[-1])
ans[-1].sort()
print((ans[-1][k - d - 1]))

-l = len(ans[-1]) -v = sorted([int(i) for i in ans[-1]]) -print((v[k - (d - l) - 1])) +ans[-1].sort() +print((ans[-1][k - d - 1]))