import queue

n = int(eval(input()))

q = queue.Queue()

count=0

p=0

for i in range(1,10):

    q.put(i)

while count!=n:

    count+=1

    a = q.get()

    p = a

    str_a = str(a)

    if str_a[-1]=='0':

        q.put(a*10)

        q.put(a*10+1)

    elif str_a[-1]=='9':

        q.put(a*10+8)

        q.put(a*10+9)

    else:

        q.put(a*10 + int(str_a[-1])-1)

        q.put(a*10 + int(str_a[-1]))

        q.put(a*10 + int(str_a[-1])+1)

print(p)







import queue



k = int(eval(input()))

q = queue.Queue()



for i in range(1,10):

    q.put(i)



count = 0

while count < k:

    num = q.get()

    num_1 = int((str(num))[-1])

    if num_1 ==0:

        q.put(num*10)

        q.put(num*10+1)

    elif num_1==9:

        q.put(num*10+num_1-1)

        q.put(num*10+num_1)

    else:

        q.put(num*10+num_1-1)

        q.put(num*10+num_1)

        q.put(num*10+num_1+1)

    count+=1

    if k==count:

        ans = num

print(ans)

    



import queue

n = int(eval(input()))
q = queue.Queue()
count = 0
p = 0
for i in range(1, 10):
    q.put(i)
while count != n:
    count += 1
    a = q.get()
    p = a
    str_a = str(a)
    if str_a[-1] == "0":
        q.put(a * 10)
        q.put(a * 10 + 1)
    elif str_a[-1] == "9":
        q.put(a * 10 + 8)
        q.put(a * 10 + 9)
    else:
        q.put(a * 10 + int(str_a[-1]) - 1)
        q.put(a * 10 + int(str_a[-1]))
        q.put(a * 10 + int(str_a[-1]) + 1)
print(p)

import queue

k = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
count = 0
while count < k:
    num = q.get()
    num_1 = int((str(num))[-1])
    if num_1 == 0:
        q.put(num * 10)
        q.put(num * 10 + 1)
    elif num_1 == 9:
        q.put(num * 10 + num_1 - 1)
        q.put(num * 10 + num_1)
    else:
        q.put(num * 10 + num_1 - 1)
        q.put(num * 10 + num_1)
        q.put(num * 10 + num_1 + 1)
    count += 1
    if k == count:
        ans = num
print(ans)

-n = int(eval(input())) +k = int(eval(input())) -count = 0 -p = 0 -while count != n: +count = 0 +while count < k: +    num = q.get() +    num_1 = int((str(num))[-1]) +    if num_1 == 0: +        q.put(num * 10) +        q.put(num * 10 + 1) +    elif num_1 == 9: +        q.put(num * 10 + num_1 - 1) +        q.put(num * 10 + num_1) +    else: +        q.put(num * 10 + num_1 - 1) +        q.put(num * 10 + num_1) +        q.put(num * 10 + num_1 + 1) -    a = q.get() -    p = a -    str_a = str(a) -    if str_a[-1] == "0": -        q.put(a * 10) -        q.put(a * 10 + 1) -    elif str_a[-1] == "9": -        q.put(a * 10 + 8) -        q.put(a * 10 + 9) -    else: -        q.put(a * 10 + int(str_a[-1]) - 1) -        q.put(a * 10 + int(str_a[-1])) -        q.put(a * 10 + int(str_a[-1]) + 1) -print(p) +    if k == count: +        ans = num +print(ans)