import collections

k = int(eval(input()))

n = 10**10



li = list(range(1,10))

num_li = li[:]

q = collections.deque(li)

count = 0



for i in range(1,n):

    num = str(q.popleft())

    go = int(num[-1])

    if go != 0:

        numa = num + str(go - 1)

        num_li.append(int(numa))

        q.append(int(numa))

        count += 1

    numa = num + str(go)

    num_li.append(int(numa))

    q.append(int(numa))

    count += 1

    if go != 9:

        numa = num + str(go + 1)

        num_li.append(int(numa))

        q.append(int(numa))

        count += 1



    if count > k+1:

        break



print((num_li[k-1]))
import collections



k = int(eval(input()))



li = [str(i) for i in range(1,10)]

st_li = li[:]

q = collections.deque(li)

count = 0

n = 10 ** 10



for i in range(1, n):

    a = q.popleft()

    num = int(a[-1])

    if num != 0:

        aa = a + str(num-1)

        st_li.append(aa)

        q.append(aa)

        count += 1

    aa = a + str(num)

    st_li.append(aa)

    q.append(aa)

    count += 1

    if num != 9:

        aa = a + str(num+1)

        st_li.append(aa)

        q.append(aa)

        count += 1

    if count > k+1:

        print((st_li[k - 1]))

        exit(0)
import collections

k = int(eval(input()))
n = 10**10
li = list(range(1, 10))
num_li = li[:]
q = collections.deque(li)
count = 0
for i in range(1, n):
    num = str(q.popleft())
    go = int(num[-1])
    if go != 0:
        numa = num + str(go - 1)
        num_li.append(int(numa))
        q.append(int(numa))
        count += 1
    numa = num + str(go)
    num_li.append(int(numa))
    q.append(int(numa))
    count += 1
    if go != 9:
        numa = num + str(go + 1)
        num_li.append(int(numa))
        q.append(int(numa))
        count += 1
    if count > k + 1:
        break
print((num_li[k - 1]))

import collections

k = int(eval(input()))
li = [str(i) for i in range(1, 10)]
st_li = li[:]
q = collections.deque(li)
count = 0
n = 10**10
for i in range(1, n):
    a = q.popleft()
    num = int(a[-1])
    if num != 0:
        aa = a + str(num - 1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    aa = a + str(num)
    st_li.append(aa)
    q.append(aa)
    count += 1
    if num != 9:
        aa = a + str(num + 1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    if count > k + 1:
        print((st_li[k - 1]))
        exit(0)

-n = 10**10 -li = list(range(1, 10)) -num_li = li[:] +li = [str(i) for i in range(1, 10)] +st_li = li[:] +n = 10**10 -    num = str(q.popleft()) -    go = int(num[-1]) -    if go != 0: -        numa = num + str(go - 1) -        num_li.append(int(numa)) -        q.append(int(numa)) +    a = q.popleft() +    num = int(a[-1]) +    if num != 0: +        aa = a + str(num - 1) +        st_li.append(aa) +        q.append(aa) -    numa = num + str(go) -    num_li.append(int(numa)) -    q.append(int(numa)) +    aa = a + str(num) +    st_li.append(aa) +    q.append(aa) -    if go != 9: -        numa = num + str(go + 1) -        num_li.append(int(numa)) -        q.append(int(numa)) +    if num != 9: +        aa = a + str(num + 1) +        st_li.append(aa) +        q.append(aa) -        break -print((num_li[k - 1])) +        print((st_li[k - 1])) +        exit(0)