from collections import deque

K = int(eval(input()))

if K<10:

  print(K)

  exit()

  

q = deque([1,2,3,4,5,6,7,8,9])



cnt = 9

while q:

  n = q.popleft()

  r = n % 10

  n *= 10;

  for i in range(10):

    if abs(r - i) <= 1:

        q.append(n + i)

        cnt += 1

        if cnt == K:

          print((n+i))

          exit()
from collections import deque

k = int(eval(input()))



if k <= 9:

  print(k)

  exit()



que = deque([1,2,3,4,5,6,7,8,9])

cnt = len(que)

while cnt < k:

  x = que.popleft()

  m = x%10

  if m != 0:

    que.append(10*x+m-1)

    cnt+=1

    if cnt == k: print((que.pop())); exit();

  que.append(10*x+m)

  cnt+=1

  if cnt == k: print((que.pop())); exit();

  if m != 9:

    que.append(10*x+m+1)

    cnt+=1

    if cnt == k: print((que.pop())); exit();
from collections import deque

K = int(eval(input()))
if K < 10:
    print(K)
    exit()
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
cnt = 9
while q:
    n = q.popleft()
    r = n % 10
    n *= 10
    for i in range(10):
        if abs(r - i) <= 1:
            q.append(n + i)
            cnt += 1
            if cnt == K:
                print((n + i))
                exit()

from collections import deque

k = int(eval(input()))
if k <= 9:
    print(k)
    exit()
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
cnt = len(que)
while cnt < k:
    x = que.popleft()
    m = x % 10
    if m != 0:
        que.append(10 * x + m - 1)
        cnt += 1
        if cnt == k:
            print((que.pop()))
            exit()
    que.append(10 * x + m)
    cnt += 1
    if cnt == k:
        print((que.pop()))
        exit()
    if m != 9:
        que.append(10 * x + m + 1)
        cnt += 1
        if cnt == k:
            print((que.pop()))
            exit()

-K = int(eval(input())) -if K < 10: -    print(K) +k = int(eval(input())) +if k <= 9: +    print(k) -q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -cnt = 9 -while q: -    n = q.popleft() -    r = n % 10 -    n *= 10 -    for i in range(10): -        if abs(r - i) <= 1: -            q.append(n + i) -            cnt += 1 -            if cnt == K: -                print((n + i)) -                exit() +que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) +cnt = len(que) +while cnt < k: +    x = que.popleft() +    m = x % 10 +    if m != 0: +        que.append(10 * x + m - 1) +        cnt += 1 +        if cnt == k: +            print((que.pop())) +            exit() +    que.append(10 * x + m) +    cnt += 1 +    if cnt == k: +        print((que.pop())) +        exit() +    if m != 9: +        que.append(10 * x + m + 1) +        cnt += 1 +        if cnt == k: +            print((que.pop())) +            exit()