k=int(eval(input()))

#a,b=map(int,input().split())

#l=list(map(int,input().split()))

#l=[list(map(int,input().split())) for i in range(n)]



from collections import deque



q=deque([1,2,3,4,5,6,7,8,9])

ansl=[]

s=1

while len(str(s))<=10:

    s=q.popleft()

    ansl.append(s)

    sl=list(str(s))

    last_digit=int(sl[-1])

    for digit in range(max(0,last_digit-1),min(last_digit+1,9)+1):

        newval=int(str(s)+str(digit))

        #ansl.append(int(str(s)+str(digit)))

        q.append(newval)

print((ansl[k-1]))

k=int(eval(input()))

#n,p=map(int,input().split())

#al=list(map(int,input().split()))

#l=[list(map(int,input().split())) for i in range(n)]

#素因数分解した結果を2次元配列にして返す



all_list=[]



def rec(d,val):

    global all_list

    all_list.append(val)

    if d==10:

        return

    for j in range(-1,2,1):

        add=val%10+j

        if add>=0 and add<=9:

            rec(d+1,val*10+add)



for i in range(1,10):

    rec(1,i)

all_list.sort()

print((all_list[k-1]))
k = int(eval(input()))
# a,b=map(int,input().split())
# l=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
from collections import deque

q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
ansl = []
s = 1
while len(str(s)) <= 10:
    s = q.popleft()
    ansl.append(s)
    sl = list(str(s))
    last_digit = int(sl[-1])
    for digit in range(max(0, last_digit - 1), min(last_digit + 1, 9) + 1):
        newval = int(str(s) + str(digit))
        # ansl.append(int(str(s)+str(digit)))
        q.append(newval)
print((ansl[k - 1]))

k = int(eval(input()))
# n,p=map(int,input().split())
# al=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
# 素因数分解した結果を2次元配列にして返す
all_list = []


def rec(d, val):
    global all_list
    all_list.append(val)
    if d == 10:
        return
    for j in range(-1, 2, 1):
        add = val % 10 + j
        if add >= 0 and add <= 9:
            rec(d + 1, val * 10 + add)


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

-# a,b=map(int,input().split()) -# l=list(map(int,input().split())) +# n,p=map(int,input().split()) +# al=list(map(int,input().split())) -from collections import deque +# 素因数分解した結果を2次元配列にして返す +all_list = [] -q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -ansl = [] -s = 1 -while len(str(s)) <= 10: -    s = q.popleft() -    ansl.append(s) -    sl = list(str(s)) -    last_digit = int(sl[-1]) -    for digit in range(max(0, last_digit - 1), min(last_digit + 1, 9) + 1): -        newval = int(str(s) + str(digit)) -        # ansl.append(int(str(s)+str(digit))) -        q.append(newval) -print((ansl[k - 1])) + +def rec(d, val): +    global all_list +    all_list.append(val) +    if d == 10: +        return +    for j in range(-1, 2, 1): +        add = val % 10 + j +        if add >= 0 and add <= 9: +            rec(d + 1, val * 10 + add) + + +for i in range(1, 10): +    rec(1, i) +all_list.sort() +print((all_list[k - 1]))