def dfs(d, r):

    global l

    if d == 11:

        return

    l.append(int(r))

    for i in range(-1, 2):

        tmp = int(r[-1]) + i

        if 0 <= tmp <= 9:

            dfs(d + 1, r + str(tmp))





k = int(eval(input()))

l = []

for i in range(1, 10):

    dfs(0, str(i))

print((sorted(l)[k - 1]))
def dfs(d, r):

    global l

    if d == 11:

        return

    l.append(int(r))

    for i in range(-1, 2):

        tmp = int(r[-1]) + i

        if 0 <= tmp <= 9:

            dfs(d + 1, r + str(tmp))





k = int(eval(input()))

l = []

for i in range(1, 10):

    dfs(1, str(i))

print((sorted(l)[k - 1]))
def dfs(d, r):
    global l
    if d == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(d + 1, r + str(tmp))


k = int(eval(input()))
l = []
for i in range(1, 10):
    dfs(0, str(i))
print((sorted(l)[k - 1]))

def dfs(d, r):
    global l
    if d == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(d + 1, r + str(tmp))


k = int(eval(input()))
l = []
for i in range(1, 10):
    dfs(1, str(i))
print((sorted(l)[k - 1]))

-    dfs(0, str(i)) +    dfs(1, str(i))