import sys

from collections import deque

input=sys.stdin.readline

sys.setrecursionlimit(10**6)



lunlun=deque()



def dfs(now):

    if len(now)>10:return

    lunlun.append(int(now))

    l=now[-1]

    

    if l!="0":

        dfs(now+str(int(l)-1))

    if l!="9":

        dfs(now+str(int(l)+1))

    dfs(now+l)



k=int(input().rstrip())

for i in range(1,10):

    dfs(str(i))





print((sorted(lunlun)[k-1]))
import sys

from collections import deque

input=sys.stdin.readline

sys.setrecursionlimit(10**6)



def main():

    k=int(input().rstrip())

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

    for _ in range(k-1):

        now=lunlun.popleft()

        last=now[-1]

        if last!="0":

            lunlun.append(now+str(int(last)-1))

        lunlun.append(now+last)

        if last!="9":

            lunlun.append(now+str(int(last)+1))

        

    print((lunlun[0]))



if __name__=="__main__":

    main()
import sys
from collections import deque

input = sys.stdin.readline
sys.setrecursionlimit(10**6)
lunlun = deque()


def dfs(now):
    if len(now) > 10:
        return
    lunlun.append(int(now))
    l = now[-1]
    if l != "0":
        dfs(now + str(int(l) - 1))
    if l != "9":
        dfs(now + str(int(l) + 1))
    dfs(now + l)


k = int(input().rstrip())
for i in range(1, 10):
    dfs(str(i))
print((sorted(lunlun)[k - 1]))

import sys
from collections import deque

input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    k = int(input().rstrip())
    lunlun = deque([str(i) for i in range(1, 10)])
    for _ in range(k - 1):
        now = lunlun.popleft()
        last = now[-1]
        if last != "0":
            lunlun.append(now + str(int(last) - 1))
        lunlun.append(now + last)
        if last != "9":
            lunlun.append(now + str(int(last) + 1))
    print((lunlun[0]))


if __name__ == "__main__":
    main()

-lunlun = deque() -def dfs(now): -    if len(now) > 10: -        return -    lunlun.append(int(now)) -    l = now[-1] -    if l != "0": -        dfs(now + str(int(l) - 1)) -    if l != "9": -        dfs(now + str(int(l) + 1)) -    dfs(now + l) +def main(): +    k = int(input().rstrip()) +    lunlun = deque([str(i) for i in range(1, 10)]) +    for _ in range(k - 1): +        now = lunlun.popleft() +        last = now[-1] +        if last != "0": +            lunlun.append(now + str(int(last) - 1)) +        lunlun.append(now + last) +        if last != "9": +            lunlun.append(now + str(int(last) + 1)) +    print((lunlun[0])) -k = int(input().rstrip()) -for i in range(1, 10): -    dfs(str(i)) -print((sorted(lunlun)[k - 1])) +if __name__ == "__main__": +    main()