

from collections import deque



K = int(eval(input()))

q = deque(list(range(1, 10)))

cnt = 0

ans = 0

while True:

    u = q.popleft()

    cnt += 1

    if cnt == K:

        ans = u

        break



    ll = u % 10

    for i in range(max(0, ll - 1), min(9, ll + 1) + 1):

        q.append(u * 10 + i)



print(ans)



from collections import deque



K = int(eval(input()))

q = deque(list(range(1, 10)))

for _ in range(K - 1):

    u = q.popleft()

    n = u % 10

    for x in range(max(0, n - 1), min(9, n + 1) + 1):

        q.append(u * 10 + x)



print((q.popleft()))

from collections import deque

K = int(eval(input()))
q = deque(list(range(1, 10)))
cnt = 0
ans = 0
while True:
    u = q.popleft()
    cnt += 1
    if cnt == K:
        ans = u
        break
    ll = u % 10
    for i in range(max(0, ll - 1), min(9, ll + 1) + 1):
        q.append(u * 10 + i)
print(ans)

from collections import deque

K = int(eval(input()))
q = deque(list(range(1, 10)))
for _ in range(K - 1):
    u = q.popleft()
    n = u % 10
    for x in range(max(0, n - 1), min(9, n + 1) + 1):
        q.append(u * 10 + x)
print((q.popleft()))

-cnt = 0 -ans = 0 -while True: +for _ in range(K - 1): -    cnt += 1 -    if cnt == K: -        ans = u -        break -    ll = u % 10 -    for i in range(max(0, ll - 1), min(9, ll + 1) + 1): -        q.append(u * 10 + i) -print(ans) +    n = u % 10 +    for x in range(max(0, n - 1), min(9, n + 1) + 1): +        q.append(u * 10 + x) +print((q.popleft()))