import sys

k = int(eval(input()))

if k <= 9:

	print(k)

	sys.exit()



def judge(s):

	for i in range(1,len(s)):

		if abs(int(s[i-1]) - int(s[i])) > 1:

			return 0

	return 1



q = ['1','2','3','4','5','6','7','8','9']

cnt = 9

cond = False

while True:



	cp = q.pop(0)

	digit = int(cp[-1])

	for d in range(-1,2):

		if 0 <= digit + d <= 9:

			cnt += 1

			if cnt == k:

				ans = cp+str(digit+d)

				cond = True

				break

			q.append(cp+str(digit+d))

	

	if cond:

		break

print(ans)

import sys

from collections import deque

K = int(eval(input()))

if K <= 9:

	print(K)

	sys.exit()

q = deque(['1', '2','3','4','5','6','7','8','9'])

cnt = 0

while True:

	cp = q.popleft()

	cnt += 1

	if cnt == K:

		ans = int(cp)

		break

	r = int(cp[-1])

	for d in [-1,0,1]:

		dd = r + d

		if 0 <= dd < 10:

			q.append(cp + str(dd))



print(ans)
import sys

k = int(eval(input()))
if k <= 9:
    print(k)
    sys.exit()


def judge(s):
    for i in range(1, len(s)):
        if abs(int(s[i - 1]) - int(s[i])) > 1:
            return 0
    return 1


q = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
cnt = 9
cond = False
while True:
    cp = q.pop(0)
    digit = int(cp[-1])
    for d in range(-1, 2):
        if 0 <= digit + d <= 9:
            cnt += 1
            if cnt == k:
                ans = cp + str(digit + d)
                cond = True
                break
            q.append(cp + str(digit + d))
    if cond:
        break
print(ans)

import sys
from collections import deque

K = int(eval(input()))
if K <= 9:
    print(K)
    sys.exit()
q = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
cnt = 0
while True:
    cp = q.popleft()
    cnt += 1
    if cnt == K:
        ans = int(cp)
        break
    r = int(cp[-1])
    for d in [-1, 0, 1]:
        dd = r + d
        if 0 <= dd < 10:
            q.append(cp + str(dd))
print(ans)

+from collections import deque -k = int(eval(input())) -if k <= 9: -    print(k) +K = int(eval(input())) +if K <= 9: +    print(K) - - -def judge(s): -    for i in range(1, len(s)): -        if abs(int(s[i - 1]) - int(s[i])) > 1: -            return 0 -    return 1 - - -q = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] -cnt = 9 -cond = False +q = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) +cnt = 0 -    cp = q.pop(0) -    digit = int(cp[-1]) -    for d in range(-1, 2): -        if 0 <= digit + d <= 9: -            cnt += 1 -            if cnt == k: -                ans = cp + str(digit + d) -                cond = True -                break -            q.append(cp + str(digit + d)) -    if cond: +    cp = q.popleft() +    cnt += 1 +    if cnt == K: +        ans = int(cp) +    r = int(cp[-1]) +    for d in [-1, 0, 1]: +        dd = r + d +        if 0 <= dd < 10: +            q.append(cp + str(dd))