k = int(eval(input()))



def dfs(d, val, A):

	A.append(val)



	if d == 10:

		return



	for i in range(-1, 2):

		add = (val % 10) + i

		if add >= 0 and add <= 9:

			dfs(d + 1, val * 10 + add, A)



A = []

for v in range(1, 10): # 呼び出し

	dfs(1, v, A)

A.sort()

print((A[k - 1]))


def calc_next(arr):

	res = []

	for val in arr:

		for j in range(-1, 2):

			add = (val % 10) + j

			if add >= 0 and add <= 9:

				res.append(val * 10 + add)

	return res



k = int(eval(input()))

cur = []

A = []



for v in range(1, 10):

	cur.append(v)

	A.append(v)



for d in range(1, 10):

	cur = calc_next(cur)

	for val in cur:

		A.append(val)



print((A[k - 1]))
k = int(eval(input()))


def dfs(d, val, A):
    A.append(val)
    if d == 10:
        return
    for i in range(-1, 2):
        add = (val % 10) + i
        if add >= 0 and add <= 9:
            dfs(d + 1, val * 10 + add, A)


A = []
for v in range(1, 10):  # 呼び出し
    dfs(1, v, A)
A.sort()
print((A[k - 1]))

def calc_next(arr):
    res = []
    for val in arr:
        for j in range(-1, 2):
            add = (val % 10) + j
            if add >= 0 and add <= 9:
                res.append(val * 10 + add)
    return res


k = int(eval(input()))
cur = []
A = []
for v in range(1, 10):
    cur.append(v)
    A.append(v)
for d in range(1, 10):
    cur = calc_next(cur)
    for val in cur:
        A.append(val)
print((A[k - 1]))

-k = int(eval(input())) +def calc_next(arr): +    res = [] +    for val in arr: +        for j in range(-1, 2): +            add = (val % 10) + j +            if add >= 0 and add <= 9: +                res.append(val * 10 + add) +    return res -def dfs(d, val, A): -    A.append(val) -    if d == 10: -        return -    for i in range(-1, 2): -        add = (val % 10) + i -        if add >= 0 and add <= 9: -            dfs(d + 1, val * 10 + add, A) - - +k = int(eval(input())) +cur = [] -for v in range(1, 10):  # 呼び出し -    dfs(1, v, A) -A.sort() +for v in range(1, 10): +    cur.append(v) +    A.append(v) +for d in range(1, 10): +    cur = calc_next(cur) +    for val in cur: +        A.append(val)