N = int(eval(input()))

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

ans = list(tmp)

for i in range(10):

    tmp2 = []

    for x in tmp:

        k = int(str(x)[-1])

        if k != 0:

            ans.append(10*x-1 + k)

            tmp2.append(10*x-1 + k)

        if k != 9:

            tmp2.append(10*x+1 + k)

            ans.append(10*x+1 + k)

        tmp2.append(10*x + k)

        ans.append(10*x + k)

    tmp = list(tmp2)



ans.sort()

print((ans[N-1]))

import collections

K = int(eval(input()))



q = collections.deque([i for i in range(1, 10)])

count = 0

while(q):

    count += 1

    x = q.popleft()

    if count == K:

        print(x)

        break

    if x % 10 != 0:

        q.append(x*10 + (x % 10 - 1))

    q.append(x*10 + (x % 10))

    if x % 10 != 9:

        q.append(x*10 + (x % 10 + 1))

N = int(eval(input()))
tmp = [i for i in range(1, 10)]
ans = list(tmp)
for i in range(10):
    tmp2 = []
    for x in tmp:
        k = int(str(x)[-1])
        if k != 0:
            ans.append(10 * x - 1 + k)
            tmp2.append(10 * x - 1 + k)
        if k != 9:
            tmp2.append(10 * x + 1 + k)
            ans.append(10 * x + 1 + k)
        tmp2.append(10 * x + k)
        ans.append(10 * x + k)
    tmp = list(tmp2)
ans.sort()
print((ans[N - 1]))

import collections

K = int(eval(input()))
q = collections.deque([i for i in range(1, 10)])
count = 0
while q:
    count += 1
    x = q.popleft()
    if count == K:
        print(x)
        break
    if x % 10 != 0:
        q.append(x * 10 + (x % 10 - 1))
    q.append(x * 10 + (x % 10))
    if x % 10 != 9:
        q.append(x * 10 + (x % 10 + 1))

-N = int(eval(input())) -tmp = [i for i in range(1, 10)] -ans = list(tmp) -for i in range(10): -    tmp2 = [] -    for x in tmp: -        k = int(str(x)[-1]) -        if k != 0: -            ans.append(10 * x - 1 + k) -            tmp2.append(10 * x - 1 + k) -        if k != 9: -            tmp2.append(10 * x + 1 + k) -            ans.append(10 * x + 1 + k) -        tmp2.append(10 * x + k) -        ans.append(10 * x + k) -    tmp = list(tmp2) -ans.sort() -print((ans[N - 1])) +import collections + +K = int(eval(input())) +q = collections.deque([i for i in range(1, 10)]) +count = 0 +while q: +    count += 1 +    x = q.popleft() +    if count == K: +        print(x) +        break +    if x % 10 != 0: +        q.append(x * 10 + (x % 10 - 1)) +    q.append(x * 10 + (x % 10)) +    if x % 10 != 9: +        q.append(x * 10 + (x % 10 + 1))