from collections import deque



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

cnt = 0

l = []

used = set()



while cnt<100000:

    p = q.popleft()

    if p in used:continue

    used.add(p)

    l.append(p)

    cnt += 1

    for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):

        q.append(10*p+i)



N = int(eval(input()))

print((l[N-1]))
from collections import deque





def solve():

    N = int(eval(input()))

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

    cnt = 0

    l = []

    used = set()



    while cnt<N:

        p = q.popleft()

        if p in used:continue

        used.add(p)

        l.append(p)

        cnt += 1

        for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):

            q.append(10*p+i)



    print((l[N-1]))





if __name__ == "__main__":

    solve()

from collections import deque

q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
cnt = 0
l = []
used = set()
while cnt < 100000:
    p = q.popleft()
    if p in used:
        continue
    used.add(p)
    l.append(p)
    cnt += 1
    for i in range(max((p % 10) - 1, 0), min((p % 10) + 1, 9) + 1):
        q.append(10 * p + i)
N = int(eval(input()))
print((l[N - 1]))

from collections import deque


def solve():
    N = int(eval(input()))
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    cnt = 0
    l = []
    used = set()
    while cnt < N:
        p = q.popleft()
        if p in used:
            continue
        used.add(p)
        l.append(p)
        cnt += 1
        for i in range(max((p % 10) - 1, 0), min((p % 10) + 1, 9) + 1):
            q.append(10 * p + i)
    print((l[N - 1]))


if __name__ == "__main__":
    solve()

-q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -cnt = 0 -l = [] -used = set() -while cnt < 100000: -    p = q.popleft() -    if p in used: -        continue -    used.add(p) -    l.append(p) -    cnt += 1 -    for i in range(max((p % 10) - 1, 0), min((p % 10) + 1, 9) + 1): -        q.append(10 * p + i) -N = int(eval(input())) -print((l[N - 1])) + +def solve(): +    N = int(eval(input())) +    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) +    cnt = 0 +    l = [] +    used = set() +    while cnt < N: +        p = q.popleft() +        if p in used: +            continue +        used.add(p) +        l.append(p) +        cnt += 1 +        for i in range(max((p % 10) - 1, 0), min((p % 10) + 1, 9) + 1): +            q.append(10 * p + i) +    print((l[N - 1])) + + +if __name__ == "__main__": +    solve()