def main():

    from functools import lru_cache

    import sys



    sys.setrecursionlimit(10 ** 7)



    @lru_cache(maxsize=None)

    def make_number(digit, p=0):

        if digit == 0:

            memo.append(p)

            if len(memo) == k + 1:

                print(p)

                exit()

            return



        if p == 0:

            # 前の位がない

            for x in range(1, 10):

                make_number(digit - 1, x)



        else:

            r = p % 10

            # 前の位がある

            for x in range(max(0, r - 1), min(9, r + 1) + 1):

                make_number(digit - 1, p * 10 + x)



    k = int(eval(input()))



    memo = []



    for digit in range(11):

        make_number(digit)





if __name__ == '__main__':

    main()



# import sys

#

# sys.setrecursionlimit(10 ** 7)

#

# input = sys.stdin.readline

# rstrip()

# int(input())

# map(int, input().split())

from collections import deque



K = int(eval(input()))



dq = deque()

for x in range(1, 10):

    dq.append(x)



idx = 1

while idx < K:

    x = dq.popleft()

    idx += 1



    r = x % 10



    if r > 0:

        nx = (x * 10) + (r - 1)

        dq.append(nx)



    nx = (x * 10) + (r)

    dq.append(nx)



    if r < 9:

        nx = (x * 10) + (r + 1)

        dq.append(nx)



ans = dq.popleft()

print(ans)

def main():
    from functools import lru_cache
    import sys

    sys.setrecursionlimit(10**7)

    @lru_cache(maxsize=None)
    def make_number(digit, p=0):
        if digit == 0:
            memo.append(p)
            if len(memo) == k + 1:
                print(p)
                exit()
            return
        if p == 0:
            # 前の位がない
            for x in range(1, 10):
                make_number(digit - 1, x)
        else:
            r = p % 10
            # 前の位がある
            for x in range(max(0, r - 1), min(9, r + 1) + 1):
                make_number(digit - 1, p * 10 + x)

    k = int(eval(input()))
    memo = []
    for digit in range(11):
        make_number(digit)


if __name__ == "__main__":
    main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

from collections import deque

K = int(eval(input()))
dq = deque()
for x in range(1, 10):
    dq.append(x)
idx = 1
while idx < K:
    x = dq.popleft()
    idx += 1
    r = x % 10
    if r > 0:
        nx = (x * 10) + (r - 1)
        dq.append(nx)
    nx = (x * 10) + (r)
    dq.append(nx)
    if r < 9:
        nx = (x * 10) + (r + 1)
        dq.append(nx)
ans = dq.popleft()
print(ans)

-def main(): -    from functools import lru_cache -    import sys +from collections import deque -    sys.setrecursionlimit(10**7) - -    @lru_cache(maxsize=None) -    def make_number(digit, p=0): -        if digit == 0: -            memo.append(p) -            if len(memo) == k + 1: -                print(p) -                exit() -            return -        if p == 0: -            # 前の位がない -            for x in range(1, 10): -                make_number(digit - 1, x) -        else: -            r = p % 10 -            # 前の位がある -            for x in range(max(0, r - 1), min(9, r + 1) + 1): -                make_number(digit - 1, p * 10 + x) - -    k = int(eval(input())) -    memo = [] -    for digit in range(11): -        make_number(digit) - - -if __name__ == "__main__": -    main() -# import sys -# -# sys.setrecursionlimit(10 ** 7) -# -# input = sys.stdin.readline -# rstrip() -# int(input()) -# map(int, input().split()) +K = int(eval(input())) +dq = deque() +for x in range(1, 10): +    dq.append(x) +idx = 1 +while idx < K: +    x = dq.popleft() +    idx += 1 +    r = x % 10 +    if r > 0: +        nx = (x * 10) + (r - 1) +        dq.append(nx) +    nx = (x * 10) + (r) +    dq.append(nx) +    if r < 9: +        nx = (x * 10) + (r + 1) +        dq.append(nx) +ans = dq.popleft() +print(ans)