K = int(eval(input()))

queue = []

for i in range(1, 10):

  queue.append(i)



while K != 0:

  if K <= len(queue):

    print((queue[K-1]))

    exit(0)



  K -= 1

  num = queue.pop(0)



  if K == 0:

    print(num)

    exit(0)



  o = int(str(num)[-1])

  for n in [o-1, o, o+1]:

    if n == -1 or n == 10: continue

    queue.append( int(str(num)+str(n)) )
from collections import deque



K = int(eval(input()))

queue = deque([i for i in range(1,10)])



while K != 0:

  if K <= len(queue):

    print((queue[K-1]))

    exit(0)



  K -= 1

  num = queue.popleft()



  o = int(str(num)[-1])

  for n in [o-1, o, o+1]:

    if n == -1 or n == 10: continue

    queue.append( int(str(num)+str(n)) )
K = int(eval(input()))
queue = []
for i in range(1, 10):
    queue.append(i)
while K != 0:
    if K <= len(queue):
        print((queue[K - 1]))
        exit(0)
    K -= 1
    num = queue.pop(0)
    if K == 0:
        print(num)
        exit(0)
    o = int(str(num)[-1])
    for n in [o - 1, o, o + 1]:
        if n == -1 or n == 10:
            continue
        queue.append(int(str(num) + str(n)))

from collections import deque

K = int(eval(input()))
queue = deque([i for i in range(1, 10)])
while K != 0:
    if K <= len(queue):
        print((queue[K - 1]))
        exit(0)
    K -= 1
    num = queue.popleft()
    o = int(str(num)[-1])
    for n in [o - 1, o, o + 1]:
        if n == -1 or n == 10:
            continue
        queue.append(int(str(num) + str(n)))

+from collections import deque + -queue = [] -for i in range(1, 10): -    queue.append(i) +queue = deque([i for i in range(1, 10)]) -    num = queue.pop(0) -    if K == 0: -        print(num) -        exit(0) +    num = queue.popleft()