from collections import deque



K = int(eval(input()))

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



ans = 0

while True:

    v = dque.popleft()

    ans += 1

    if ans == K:

        print(v)

        exit(0)



    strv = str(v)

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

        dque.append(int(strv+'0'))

        dque.append(int(strv+'1'))

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

        dque.append(int(strv+'8'))

        dque.append(int(strv+'9'))

    else:

        endv = int(strv[-1])

        dque.append(int(strv+str(endv-1)))

        dque.append(int(strv+str(endv)))

        dque.append(int(strv+str(endv+1)))

from collections import deque



K = int(eval(input()))

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



ans = 0

while True:

    v = dque.popleft()

    ans += 1

    if ans == K:

        print(v)

        exit(0)



    for i in range(-1, 2):

        # 10で割った余りを取得して、iを足す

        tmp = v % 10+i

        if not(0 <= tmp <= 9):

            continue

        dque.append(v*10+tmp)
from collections import deque

K = int(eval(input()))
dque = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
ans = 0
while True:
    v = dque.popleft()
    ans += 1
    if ans == K:
        print(v)
        exit(0)
    strv = str(v)
    if strv[-1] == "0":
        dque.append(int(strv + "0"))
        dque.append(int(strv + "1"))
    elif strv[-1] == "9":
        dque.append(int(strv + "8"))
        dque.append(int(strv + "9"))
    else:
        endv = int(strv[-1])
        dque.append(int(strv + str(endv - 1)))
        dque.append(int(strv + str(endv)))
        dque.append(int(strv + str(endv + 1)))

from collections import deque

K = int(eval(input()))
dque = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
ans = 0
while True:
    v = dque.popleft()
    ans += 1
    if ans == K:
        print(v)
        exit(0)
    for i in range(-1, 2):
        # 10で割った余りを取得して、iを足す
        tmp = v % 10 + i
        if not (0 <= tmp <= 9):
            continue
        dque.append(v * 10 + tmp)

-    strv = str(v) -    if strv[-1] == "0": -        dque.append(int(strv + "0")) -        dque.append(int(strv + "1")) -    elif strv[-1] == "9": -        dque.append(int(strv + "8")) -        dque.append(int(strv + "9")) -    else: -        endv = int(strv[-1]) -        dque.append(int(strv + str(endv - 1))) -        dque.append(int(strv + str(endv))) -        dque.append(int(strv + str(endv + 1))) +    for i in range(-1, 2): +        # 10で割った余りを取得して、iを足す +        tmp = v % 10 + i +        if not (0 <= tmp <= 9): +            continue +        dque.append(v * 10 + tmp)