def lunlun(n):

	nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])

	while len(nums) < n:

		old_nums = list(nums)

		for num in old_nums:

			num = str(num)

			if num[-1] == '0':

				adds = num + '0'

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + '1'

				if int(adds) not in nums:

					nums.add(int(adds))

			elif num[-1] == '9':

				adds = num + '9'

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + '8'

				if int(adds) not in nums:

					nums.add(int(adds))

			else:

				adds = num + str(int(num[-1]) - 1)

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + str(int(num[-1]))

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + str(int(num[-1]) + 1)

				if int(adds) not in nums:

					nums.add(int(adds))

			if num[0] == '1':

				adds = '1' + num

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = '2' + num

				if int(adds) not in nums:

					nums.add(int(adds))

			elif num[0] == '9':

				adds = '8' + num

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = '9' + num

				if int(adds) not in nums:

					nums.add(int(adds))

			else:

				adds = str(int(num[0]) - 1) + num

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = str(int(num[0])) + num

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = str(int(num[0]) + 1) + num

				if int(adds) not in nums:

					nums.add(int(adds))



	nums = list(nums)

	nums = sorted(nums)

	return nums[n - 1]



n = int(eval(input()))

print((lunlun(n)))
def lunlun(n):

	nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])

	while len(nums) < n:

		old_nums = list(nums)

		for num in old_nums:

			num = str(num)

			if num[-1] == '0':

				adds = num + '0'

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + '1'

				if int(adds) not in nums:

					nums.add(int(adds))

			elif num[-1] == '9':

				adds = num + '9'

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + '8'

				if int(adds) not in nums:

					nums.add(int(adds))

			else:

				adds = num + str(int(num[-1]) - 1)

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + str(int(num[-1]))

				if int(adds) not in nums:

					nums.add(int(adds))

				adds = num + str(int(num[-1]) + 1)

				if int(adds) not in nums:

					nums.add(int(adds))

			# if num[0] == '1':

			# 	adds = '1' + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))

			# 	adds = '2' + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))

			# elif num[0] == '9':

			# 	adds = '8' + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))

			# 	adds = '9' + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))

			# else:

			# 	adds = str(int(num[0]) - 1) + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))

			# 	adds = str(int(num[0])) + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))

			# 	adds = str(int(num[0]) + 1) + num

			# 	if int(adds) not in nums:

			# 		nums.add(int(adds))



	nums = list(nums)

	nums = sorted(nums)

	return nums[n - 1]



n = int(eval(input()))

print((lunlun(n)))
def lunlun(n):
    nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
    while len(nums) < n:
        old_nums = list(nums)
        for num in old_nums:
            num = str(num)
            if num[-1] == "0":
                adds = num + "0"
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + "1"
                if int(adds) not in nums:
                    nums.add(int(adds))
            elif num[-1] == "9":
                adds = num + "9"
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + "8"
                if int(adds) not in nums:
                    nums.add(int(adds))
            else:
                adds = num + str(int(num[-1]) - 1)
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + str(int(num[-1]))
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + str(int(num[-1]) + 1)
                if int(adds) not in nums:
                    nums.add(int(adds))
            if num[0] == "1":
                adds = "1" + num
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = "2" + num
                if int(adds) not in nums:
                    nums.add(int(adds))
            elif num[0] == "9":
                adds = "8" + num
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = "9" + num
                if int(adds) not in nums:
                    nums.add(int(adds))
            else:
                adds = str(int(num[0]) - 1) + num
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = str(int(num[0])) + num
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = str(int(num[0]) + 1) + num
                if int(adds) not in nums:
                    nums.add(int(adds))
    nums = list(nums)
    nums = sorted(nums)
    return nums[n - 1]


n = int(eval(input()))
print((lunlun(n)))

def lunlun(n):
    nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
    while len(nums) < n:
        old_nums = list(nums)
        for num in old_nums:
            num = str(num)
            if num[-1] == "0":
                adds = num + "0"
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + "1"
                if int(adds) not in nums:
                    nums.add(int(adds))
            elif num[-1] == "9":
                adds = num + "9"
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + "8"
                if int(adds) not in nums:
                    nums.add(int(adds))
            else:
                adds = num + str(int(num[-1]) - 1)
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + str(int(num[-1]))
                if int(adds) not in nums:
                    nums.add(int(adds))
                adds = num + str(int(num[-1]) + 1)
                if int(adds) not in nums:
                    nums.add(int(adds))
            # if num[0] == '1':
            # 	adds = '1' + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
            # 	adds = '2' + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
            # elif num[0] == '9':
            # 	adds = '8' + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
            # 	adds = '9' + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
            # else:
            # 	adds = str(int(num[0]) - 1) + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
            # 	adds = str(int(num[0])) + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
            # 	adds = str(int(num[0]) + 1) + num
            # 	if int(adds) not in nums:
            # 		nums.add(int(adds))
    nums = list(nums)
    nums = sorted(nums)
    return nums[n - 1]


n = int(eval(input()))
print((lunlun(n)))

-            if num[0] == "1": -                adds = "1" + num -                if int(adds) not in nums: -                    nums.add(int(adds)) -                adds = "2" + num -                if int(adds) not in nums: -                    nums.add(int(adds)) -            elif num[0] == "9": -                adds = "8" + num -                if int(adds) not in nums: -                    nums.add(int(adds)) -                adds = "9" + num -                if int(adds) not in nums: -                    nums.add(int(adds)) -            else: -                adds = str(int(num[0]) - 1) + num -                if int(adds) not in nums: -                    nums.add(int(adds)) -                adds = str(int(num[0])) + num -                if int(adds) not in nums: -                    nums.add(int(adds)) -                adds = str(int(num[0]) + 1) + num -                if int(adds) not in nums: -                    nums.add(int(adds)) +            # if num[0] == '1': +            # 	adds = '1' + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds)) +            # 	adds = '2' + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds)) +            # elif num[0] == '9': +            # 	adds = '8' + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds)) +            # 	adds = '9' + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds)) +            # else: +            # 	adds = str(int(num[0]) - 1) + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds)) +            # 	adds = str(int(num[0])) + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds)) +            # 	adds = str(int(num[0]) + 1) + num +            # 	if int(adds) not in nums: +            # 		nums.add(int(adds))