K=int(eval(input()))



from collections import deque



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



k=1

while True:

    a=d.popleft()

    if k==K:

        print(a)

        exit()

    else:

        k+=1

    r=a%10

    if r==0:

        for i in [0,1]:

            temp=a*10+i

            d.append(temp)

    elif r==9:

        for i in [8,9]:

            temp=a*10+i

            d.append(temp)

    else:

        for i in [-1,0,1]:

            temp=a*10+(r+i)

            d.append(temp)

K=int(eval(input()))



from collections import deque



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



k=1

while True:

    a=d.popleft()

    if k==K:

        print(a)

        exit()

    else:

        k+=1

    r=a%10

    if 0<r<=9:

        temp = a * 10 + (r -1)

        d.append(temp)

    temp=a*10+r

    d.append(temp)

    if 0<=r<9:

        temp=a*10+(r+1)

        d.append(temp)

K = int(eval(input()))
from collections import deque

d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
k = 1
while True:
    a = d.popleft()
    if k == K:
        print(a)
        exit()
    else:
        k += 1
    r = a % 10
    if r == 0:
        for i in [0, 1]:
            temp = a * 10 + i
            d.append(temp)
    elif r == 9:
        for i in [8, 9]:
            temp = a * 10 + i
            d.append(temp)
    else:
        for i in [-1, 0, 1]:
            temp = a * 10 + (r + i)
            d.append(temp)

K = int(eval(input()))
from collections import deque

d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
k = 1
while True:
    a = d.popleft()
    if k == K:
        print(a)
        exit()
    else:
        k += 1
    r = a % 10
    if 0 < r <= 9:
        temp = a * 10 + (r - 1)
        d.append(temp)
    temp = a * 10 + r
    d.append(temp)
    if 0 <= r < 9:
        temp = a * 10 + (r + 1)
        d.append(temp)

-    if r == 0: -        for i in [0, 1]: -            temp = a * 10 + i -            d.append(temp) -    elif r == 9: -        for i in [8, 9]: -            temp = a * 10 + i -            d.append(temp) -    else: -        for i in [-1, 0, 1]: -            temp = a * 10 + (r + i) -            d.append(temp) +    if 0 < r <= 9: +        temp = a * 10 + (r - 1) +        d.append(temp) +    temp = a * 10 + r +    d.append(temp) +    if 0 <= r < 9: +        temp = a * 10 + (r + 1) +        d.append(temp)