import os

import sys



from functools import lru_cache



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(10 ** 9)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7





# MOD = 998244353





def is_ok(n):

    s = str(n)

    ok = True

    for a, b in zip(s, s[1:]):

        if not abs(int(a) - int(b)) <= 1:

            return False

    return True





@lru_cache(maxsize=None)

def rekkyo(n, d):

    if d == 0:

        return ['']

    ret = []

    if n > 0:

        for s in rekkyo(n - 1, d - 1):

            ret.append(str(n - 1) + s)

    for s in rekkyo(n, d - 1):

        ret.append(str(n) + s)

    if n < 9:

        for s in rekkyo(n + 1, d - 1):

            ret.append(str(n + 1) + s)

    return ret





K = int(sys.stdin.buffer.readline())



s = set()

for i in range(10):

    for j in range(1,11):

        a = rekkyo(i, j)

        s |= set(a)

a = list(sorted(set(list(map(int, s)))))

print((a[K]))

# for aa in a:

#     print(aa)

import os

import sys

from collections import deque



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(10 ** 9)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7

# MOD = 998244353



# 解説

K = int(sys.stdin.buffer.readline())

que = deque(list(map(str, list(range(1, 10)))))

for _ in range(K - 1):

    # print(que)

    s = que.popleft()

    d = int(s[-1])

    if d > 0:

        que.append(s + str(d - 1))

    que.append(s + str(d))

    if d < 9:

        que.append(s + str(d + 1))

print((int(que[0])))

import os
import sys
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
def is_ok(n):
    s = str(n)
    ok = True
    for a, b in zip(s, s[1:]):
        if not abs(int(a) - int(b)) <= 1:
            return False
    return True


@lru_cache(maxsize=None)
def rekkyo(n, d):
    if d == 0:
        return [""]
    ret = []
    if n > 0:
        for s in rekkyo(n - 1, d - 1):
            ret.append(str(n - 1) + s)
    for s in rekkyo(n, d - 1):
        ret.append(str(n) + s)
    if n < 9:
        for s in rekkyo(n + 1, d - 1):
            ret.append(str(n + 1) + s)
    return ret


K = int(sys.stdin.buffer.readline())
s = set()
for i in range(10):
    for j in range(1, 11):
        a = rekkyo(i, j)
        s |= set(a)
a = list(sorted(set(list(map(int, s)))))
print((a[K]))
# for aa in a:
#     print(aa)

import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
# 解説
K = int(sys.stdin.buffer.readline())
que = deque(list(map(str, list(range(1, 10)))))
for _ in range(K - 1):
    # print(que)
    s = que.popleft()
    d = int(s[-1])
    if d > 0:
        que.append(s + str(d - 1))
    que.append(s + str(d))
    if d < 9:
        que.append(s + str(d + 1))
print((int(que[0])))

-from functools import lru_cache +from collections import deque -def is_ok(n): -    s = str(n) -    ok = True -    for a, b in zip(s, s[1:]): -        if not abs(int(a) - int(b)) <= 1: -            return False -    return True - - -@lru_cache(maxsize=None) -def rekkyo(n, d): -    if d == 0: -        return [""] -    ret = [] -    if n > 0: -        for s in rekkyo(n - 1, d - 1): -            ret.append(str(n - 1) + s) -    for s in rekkyo(n, d - 1): -        ret.append(str(n) + s) -    if n < 9: -        for s in rekkyo(n + 1, d - 1): -            ret.append(str(n + 1) + s) -    return ret - - +# 解説 -s = set() -for i in range(10): -    for j in range(1, 11): -        a = rekkyo(i, j) -        s |= set(a) -a = list(sorted(set(list(map(int, s))))) -print((a[K])) -# for aa in a: -#     print(aa) +que = deque(list(map(str, list(range(1, 10))))) +for _ in range(K - 1): +    # print(que) +    s = que.popleft() +    d = int(s[-1]) +    if d > 0: +        que.append(s + str(d - 1)) +    que.append(s + str(d)) +    if d < 9: +        que.append(s + str(d + 1)) +print((int(que[0])))