from collections import deque



def dfs(q, keta):

    global K

    

    if len(q)==keta:

        K -= 1

        

        if K==0:

            q = list(map(str, q))

            print((''.join(q)))

            exit()

        

        return

    

    for nex in range(max(0, q[-1]-1), min(9, q[-1]+1)+1):

        q.append(nex)

        dfs(q, keta)

        q.pop()



K = int(eval(input()))



for i in range(1, 100):

    for j in range(1, 10):

        q = deque([j])

        dfs(q, i)
import sys

input = sys.stdin.readline

from collections import deque



K = int(eval(input()))

q = deque([])



for i in range(1, 10):

    q.append(i)



cnt = 0

    

while q:

    v = q.popleft()

    cnt += 1

    

    if cnt==K:

        print(v)

        exit()

    

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

        q.append(10*v+i)

from collections import deque


def dfs(q, keta):
    global K
    if len(q) == keta:
        K -= 1
        if K == 0:
            q = list(map(str, q))
            print(("".join(q)))
            exit()
        return
    for nex in range(max(0, q[-1] - 1), min(9, q[-1] + 1) + 1):
        q.append(nex)
        dfs(q, keta)
        q.pop()


K = int(eval(input()))
for i in range(1, 100):
    for j in range(1, 10):
        q = deque([j])
        dfs(q, i)

import sys

input = sys.stdin.readline
from collections import deque

K = int(eval(input()))
q = deque([])
for i in range(1, 10):
    q.append(i)
cnt = 0
while q:
    v = q.popleft()
    cnt += 1
    if cnt == K:
        print(v)
        exit()
    for i in range(max(0, v % 10 - 1), min(9, v % 10 + 1) + 1):
        q.append(10 * v + i)

+import sys + +input = sys.stdin.readline - -def dfs(q, keta): -    global K -    if len(q) == keta: -        K -= 1 -        if K == 0: -            q = list(map(str, q)) -            print(("".join(q))) -            exit() -        return -    for nex in range(max(0, q[-1] - 1), min(9, q[-1] + 1) + 1): -        q.append(nex) -        dfs(q, keta) -        q.pop() - - -for i in range(1, 100): -    for j in range(1, 10): -        q = deque([j]) -        dfs(q, i) +q = deque([]) +for i in range(1, 10): +    q.append(i) +cnt = 0 +while q: +    v = q.popleft() +    cnt += 1 +    if cnt == K: +        print(v) +        exit() +    for i in range(max(0, v % 10 - 1), min(9, v % 10 + 1) + 1): +        q.append(10 * v + i)