import sys

from collections import deque



def solve():

      input = sys.stdin.readline

      K = int(eval(input()))

      low, high = 0, 3234566668

      while high - low > 1:

            mid = (low + high) // 2

            midS = str(mid)

            lenS = len(midS)

            q = deque()

            for j in range(lenS):

                  for i in range(1, 10): q.append((i, i, j + 1))

            count = 0

            isRunrun = False

            while q:

                  ns, last, length = q.pop()

                  if length == lenS:

                        if ns <= mid: count += 1

                        if ns == mid: isRunrun = True

                  else:

                        if last == 0: 

                              q.append((ns*10 + 1, 1, length + 1))

                              q.append((ns*10 + 0, 0, length + 1))

                        elif last == 9: 

                              q.append((ns*10 + 8, 8, length + 1))

                              q.append((ns*10 + 9, 9, length + 1))

                        else:

                              q.append((ns*10 + last+1, last + 1, length + 1))

                              q.append((ns*10 + last-1, last - 1, length + 1))

                              q.append((ns*10 + last, last, length + 1))

            if count > K: high = mid

            elif count == K:

                  if isRunrun: low = mid

                  else: high = mid

            else: low = mid

            #print(mid, count)

      print(low)

            

      return 0



if __name__ == "__main__":

      solve()
import sys

from collections import deque



def solve():

    input = sys.stdin.readline

    K = int(eval(input()))

    q = deque()

    for i in range(9): q.append((i + 1, i + 1))

    lunlun = 1

    while lunlun < K:

        nowNum, lastNum = q.popleft()

        if lastNum > 0: q.append((nowNum * 10 + lastNum - 1, lastNum - 1))

        q.append((nowNum * 10 + lastNum, lastNum))

        if lastNum < 9: q.append((nowNum * 10 + lastNum + 1, lastNum + 1))

        lunlun += 1

    ans, lastNum = q.popleft()

    print(ans)



    return 0



if __name__ == "__main__":

    solve()
import sys
from collections import deque


def solve():
    input = sys.stdin.readline
    K = int(eval(input()))
    low, high = 0, 3234566668
    while high - low > 1:
        mid = (low + high) // 2
        midS = str(mid)
        lenS = len(midS)
        q = deque()
        for j in range(lenS):
            for i in range(1, 10):
                q.append((i, i, j + 1))
        count = 0
        isRunrun = False
        while q:
            ns, last, length = q.pop()
            if length == lenS:
                if ns <= mid:
                    count += 1
                if ns == mid:
                    isRunrun = True
            else:
                if last == 0:
                    q.append((ns * 10 + 1, 1, length + 1))
                    q.append((ns * 10 + 0, 0, length + 1))
                elif last == 9:
                    q.append((ns * 10 + 8, 8, length + 1))
                    q.append((ns * 10 + 9, 9, length + 1))
                else:
                    q.append((ns * 10 + last + 1, last + 1, length + 1))
                    q.append((ns * 10 + last - 1, last - 1, length + 1))
                    q.append((ns * 10 + last, last, length + 1))
        if count > K:
            high = mid
        elif count == K:
            if isRunrun:
                low = mid
            else:
                high = mid
        else:
            low = mid
        # print(mid, count)
    print(low)
    return 0


if __name__ == "__main__":
    solve()

import sys
from collections import deque


def solve():
    input = sys.stdin.readline
    K = int(eval(input()))
    q = deque()
    for i in range(9):
        q.append((i + 1, i + 1))
    lunlun = 1
    while lunlun < K:
        nowNum, lastNum = q.popleft()
        if lastNum > 0:
            q.append((nowNum * 10 + lastNum - 1, lastNum - 1))
        q.append((nowNum * 10 + lastNum, lastNum))
        if lastNum < 9:
            q.append((nowNum * 10 + lastNum + 1, lastNum + 1))
        lunlun += 1
    ans, lastNum = q.popleft()
    print(ans)
    return 0


if __name__ == "__main__":
    solve()

-    low, high = 0, 3234566668 -    while high - low > 1: -        mid = (low + high) // 2 -        midS = str(mid) -        lenS = len(midS) -        q = deque() -        for j in range(lenS): -            for i in range(1, 10): -                q.append((i, i, j + 1)) -        count = 0 -        isRunrun = False -        while q: -            ns, last, length = q.pop() -            if length == lenS: -                if ns <= mid: -                    count += 1 -                if ns == mid: -                    isRunrun = True -            else: -                if last == 0: -                    q.append((ns * 10 + 1, 1, length + 1)) -                    q.append((ns * 10 + 0, 0, length + 1)) -                elif last == 9: -                    q.append((ns * 10 + 8, 8, length + 1)) -                    q.append((ns * 10 + 9, 9, length + 1)) -                else: -                    q.append((ns * 10 + last + 1, last + 1, length + 1)) -                    q.append((ns * 10 + last - 1, last - 1, length + 1)) -                    q.append((ns * 10 + last, last, length + 1)) -        if count > K: -            high = mid -        elif count == K: -            if isRunrun: -                low = mid -            else: -                high = mid -        else: -            low = mid -        # print(mid, count) -    print(low) +    q = deque() +    for i in range(9): +        q.append((i + 1, i + 1)) +    lunlun = 1 +    while lunlun < K: +        nowNum, lastNum = q.popleft() +        if lastNum > 0: +            q.append((nowNum * 10 + lastNum - 1, lastNum - 1)) +        q.append((nowNum * 10 + lastNum, lastNum)) +        if lastNum < 9: +            q.append((nowNum * 10 + lastNum + 1, lastNum + 1)) +        lunlun += 1 +    ans, lastNum = q.popleft() +    print(ans)