k = int(eval(input()))

lunlun = list(range(1, 10))



for i in range(k - 1):

    a = lunlun[i]

    b = a * 10 + a % 10

    if a % 10 != 0:

        lunlun.append(b - 1)

    lunlun.append(b)

    if a % 10 != 9:

        lunlun.append(b + 1)

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

li = [i + 1 for i in range(9)]



c = 0

while len(li) < k:

    if li[c] % 10 != 0:

        li.append(li[c] * 10 + li[c] % 10 - 1)

    li.append(li[c] * 10 + li[c] % 10)

    if li[c] % 10 != 9:

        li.append(li[c] * 10 + li[c] % 10 + 1)

    c += 1

print((li[k - 1]))
k = int(eval(input()))
lunlun = list(range(1, 10))
for i in range(k - 1):
    a = lunlun[i]
    b = a * 10 + a % 10
    if a % 10 != 0:
        lunlun.append(b - 1)
    lunlun.append(b)
    if a % 10 != 9:
        lunlun.append(b + 1)
print((lunlun[k - 1]))

k = int(eval(input()))
li = [i + 1 for i in range(9)]
c = 0
while len(li) < k:
    if li[c] % 10 != 0:
        li.append(li[c] * 10 + li[c] % 10 - 1)
    li.append(li[c] * 10 + li[c] % 10)
    if li[c] % 10 != 9:
        li.append(li[c] * 10 + li[c] % 10 + 1)
    c += 1
print((li[k - 1]))

-lunlun = list(range(1, 10)) -for i in range(k - 1): -    a = lunlun[i] -    b = a * 10 + a % 10 -    if a % 10 != 0: -        lunlun.append(b - 1) -    lunlun.append(b) -    if a % 10 != 9: -        lunlun.append(b + 1) -print((lunlun[k - 1])) +li = [i + 1 for i in range(9)] +c = 0 +while len(li) < k: +    if li[c] % 10 != 0: +        li.append(li[c] * 10 + li[c] % 10 - 1) +    li.append(li[c] * 10 + li[c] % 10) +    if li[c] % 10 != 9: +        li.append(li[c] * 10 + li[c] % 10 + 1) +    c += 1 +print((li[k - 1]))