def dfs(s):

    d=len(s)

    if d>10:

        return

    

    if s!='':

        if s[0]!='0':

            num.add(int(s))



    for c in '0123456789':

        if s=='':

            dfs(s+c)

        else:

            if abs(int(s[-1])-int(c))<=1:

                dfs(s+c)



k=int(eval(input()))

num=set()



dfs('')

ans=list(num)

ans.sort()

print((ans[k-1]))
from collections import deque

k=int(eval(input()))

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



ans=0

cnt=0



while 1:

    x=q.popleft()

    cnt+=1

    if cnt==k:

        ans=x

        break

    xmod10 = x % 10

    if xmod10 != 0:

        q.append(10*x+(xmod10-1))

    q.append(10*x+(xmod10))

    if xmod10 != 9:

        q.append(10*x+(xmod10+1))



print(ans)

def dfs(s):
    d = len(s)
    if d > 10:
        return
    if s != "":
        if s[0] != "0":
            num.add(int(s))
    for c in "0123456789":
        if s == "":
            dfs(s + c)
        else:
            if abs(int(s[-1]) - int(c)) <= 1:
                dfs(s + c)


k = int(eval(input()))
num = set()
dfs("")
ans = list(num)
ans.sort()
print((ans[k - 1]))

from collections import deque

k = int(eval(input()))
q = deque([i for i in range(1, 10)])
ans = 0
cnt = 0
while 1:
    x = q.popleft()
    cnt += 1
    if cnt == k:
        ans = x
        break
    xmod10 = x % 10
    if xmod10 != 0:
        q.append(10 * x + (xmod10 - 1))
    q.append(10 * x + (xmod10))
    if xmod10 != 9:
        q.append(10 * x + (xmod10 + 1))
print(ans)

-def dfs(s): -    d = len(s) -    if d > 10: -        return -    if s != "": -        if s[0] != "0": -            num.add(int(s)) -    for c in "0123456789": -        if s == "": -            dfs(s + c) -        else: -            if abs(int(s[-1]) - int(c)) <= 1: -                dfs(s + c) - +from collections import deque -num = set() -dfs("") -ans = list(num) -ans.sort() -print((ans[k - 1])) +q = deque([i for i in range(1, 10)]) +ans = 0 +cnt = 0 +while 1: +    x = q.popleft() +    cnt += 1 +    if cnt == k: +        ans = x +        break +    xmod10 = x % 10 +    if xmod10 != 0: +        q.append(10 * x + (xmod10 - 1)) +    q.append(10 * x + (xmod10)) +    if xmod10 != 9: +        q.append(10 * x + (xmod10 + 1)) +print(ans)