from collections import deque



K = int(eval(input()))

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

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



while len(ansq)<=K:

    num = d.popleft()



    if str(num)[-1] == "0":

        d.append(num*10)

        d.append(num*10+1)

        ansq.append(num*10)

        ansq.append(num*10+1)

        continue



    if str(num)[-1] == "9":

        d.append(num*10+8)

        d.append(num*10+9)

        ansq.append(num*10+8)

        ansq.append(num*10+9)

        continue



    d.append(num*10+int(str(num)[-1])-1)

    d.append(num*10+int(str(num)[-1]))

    d.append(num*10+int(str(num)[-1])+1)

    ansq.append(num*10+int(str(num)[-1])-1)

    ansq.append(num*10+int(str(num)[-1]))

    ansq.append(num*10+int(str(num)[-1])+1)

    

print((ansq[K-1]))
from collections import deque



K = int(eval(input()))

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

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



while len(ansq)<=K:

    num = d.popleft()



    if str(num)[-1] == "0":

        da = num*10

        db = num*10+1

        d.append(da)

        d.append(db)

        ansq.append(da)

        ansq.append(db)

        continue



    if str(num)[-1] == "9":

        da = num*10+8

        db = num*10+9

        d.append(da)

        d.append(db)

        ansq.append(da)

        ansq.append(db)

        continue



    da = num*10+int(str(num)[-1])-1

    db = num*10+int(str(num)[-1])

    dc = num*10+int(str(num)[-1])+1

    d.append(da)

    d.append(db)

    d.append(dc)

    ansq.append(da)

    ansq.append(db)

    ansq.append(dc)





print((ansq[K-1]))
from collections import deque

K = int(eval(input()))
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
ansq = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
while len(ansq) <= K:
    num = d.popleft()
    if str(num)[-1] == "0":
        d.append(num * 10)
        d.append(num * 10 + 1)
        ansq.append(num * 10)
        ansq.append(num * 10 + 1)
        continue
    if str(num)[-1] == "9":
        d.append(num * 10 + 8)
        d.append(num * 10 + 9)
        ansq.append(num * 10 + 8)
        ansq.append(num * 10 + 9)
        continue
    d.append(num * 10 + int(str(num)[-1]) - 1)
    d.append(num * 10 + int(str(num)[-1]))
    d.append(num * 10 + int(str(num)[-1]) + 1)
    ansq.append(num * 10 + int(str(num)[-1]) - 1)
    ansq.append(num * 10 + int(str(num)[-1]))
    ansq.append(num * 10 + int(str(num)[-1]) + 1)
print((ansq[K - 1]))

from collections import deque

K = int(eval(input()))
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
ansq = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
while len(ansq) <= K:
    num = d.popleft()
    if str(num)[-1] == "0":
        da = num * 10
        db = num * 10 + 1
        d.append(da)
        d.append(db)
        ansq.append(da)
        ansq.append(db)
        continue
    if str(num)[-1] == "9":
        da = num * 10 + 8
        db = num * 10 + 9
        d.append(da)
        d.append(db)
        ansq.append(da)
        ansq.append(db)
        continue
    da = num * 10 + int(str(num)[-1]) - 1
    db = num * 10 + int(str(num)[-1])
    dc = num * 10 + int(str(num)[-1]) + 1
    d.append(da)
    d.append(db)
    d.append(dc)
    ansq.append(da)
    ansq.append(db)
    ansq.append(dc)
print((ansq[K - 1]))

-        d.append(num * 10) -        d.append(num * 10 + 1) -        ansq.append(num * 10) -        ansq.append(num * 10 + 1) +        da = num * 10 +        db = num * 10 + 1 +        d.append(da) +        d.append(db) +        ansq.append(da) +        ansq.append(db) -        d.append(num * 10 + 8) -        d.append(num * 10 + 9) -        ansq.append(num * 10 + 8) -        ansq.append(num * 10 + 9) +        da = num * 10 + 8 +        db = num * 10 + 9 +        d.append(da) +        d.append(db) +        ansq.append(da) +        ansq.append(db) -    d.append(num * 10 + int(str(num)[-1]) - 1) -    d.append(num * 10 + int(str(num)[-1])) -    d.append(num * 10 + int(str(num)[-1]) + 1) -    ansq.append(num * 10 + int(str(num)[-1]) - 1) -    ansq.append(num * 10 + int(str(num)[-1])) -    ansq.append(num * 10 + int(str(num)[-1]) + 1) +    da = num * 10 + int(str(num)[-1]) - 1 +    db = num * 10 + int(str(num)[-1]) +    dc = num * 10 + int(str(num)[-1]) + 1 +    d.append(da) +    d.append(db) +    d.append(dc) +    ansq.append(da) +    ansq.append(db) +    ansq.append(dc)