k = int(eval(input()))

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

n = 0

while n < 9:

  rep = li[:]

  for r in rep:

    if r[-1] == "0":

      li.append(r+"0")

      li.append(r+"1")

    elif r[-1] == "9":

      li.append(r+"8")

      li.append(r+"9")

    else:

      x = int(r[-1])

      li.append(r+str(x-1))

      li.append(r+str(x))

      li.append(r+str(x+1))

  n += 1



setli = set(li)

li = list(setli)

#print(li)

intli = [int(i) for i in li]

intli.sort()

#print(intli)

#intli.sort

#print(len(intli))

#print(intli)

print((intli[k-1]))

from collections import deque

k = int(eval(input()))



def dfs(k):

  cnt = 0

  stack = deque()

  for i in range(1, 10):

    stack.append(i)

  while cnt <= k:

    q = stack.popleft()

    ans.append(q)

    cnt += 1

    l = q % 10

    for x in range(max(0, l - 1), min(10, l + 2)):

      stack.append(q * 10 + x)

          

ans = []

dfs(k)

print((ans[k-1]))
k = int(eval(input()))
li = [str(i) for i in range(1, 10)]
n = 0
while n < 9:
    rep = li[:]
    for r in rep:
        if r[-1] == "0":
            li.append(r + "0")
            li.append(r + "1")
        elif r[-1] == "9":
            li.append(r + "8")
            li.append(r + "9")
        else:
            x = int(r[-1])
            li.append(r + str(x - 1))
            li.append(r + str(x))
            li.append(r + str(x + 1))
    n += 1
setli = set(li)
li = list(setli)
# print(li)
intli = [int(i) for i in li]
intli.sort()
# print(intli)
# intli.sort
# print(len(intli))
# print(intli)
print((intli[k - 1]))

from collections import deque

k = int(eval(input()))


def dfs(k):
    cnt = 0
    stack = deque()
    for i in range(1, 10):
        stack.append(i)
    while cnt <= k:
        q = stack.popleft()
        ans.append(q)
        cnt += 1
        l = q % 10
        for x in range(max(0, l - 1), min(10, l + 2)):
            stack.append(q * 10 + x)


ans = []
dfs(k)
print((ans[k - 1]))

+from collections import deque + -li = [str(i) for i in range(1, 10)] -n = 0 -while n < 9: -    rep = li[:] -    for r in rep: -        if r[-1] == "0": -            li.append(r + "0") -            li.append(r + "1") -        elif r[-1] == "9": -            li.append(r + "8") -            li.append(r + "9") -        else: -            x = int(r[-1]) -            li.append(r + str(x - 1)) -            li.append(r + str(x)) -            li.append(r + str(x + 1)) -    n += 1 -setli = set(li) -li = list(setli) -# print(li) -intli = [int(i) for i in li] -intli.sort() -# print(intli) -# intli.sort -# print(len(intli)) -# print(intli) -print((intli[k - 1])) + + +def dfs(k): +    cnt = 0 +    stack = deque() +    for i in range(1, 10): +        stack.append(i) +    while cnt <= k: +        q = stack.popleft() +        ans.append(q) +        cnt += 1 +        l = q % 10 +        for x in range(max(0, l - 1), min(10, l + 2)): +            stack.append(q * 10 + x) + + +ans = [] +dfs(k) +print((ans[k - 1]))