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 collections import deque



    K = int(eval(input()))



    dq = deque()

    for x in range(1, 10):

        dq.append(x)



    idx = 0

    while dq:

        x = dq.popleft()

        idx += 1

        if idx == K:

            print(x)

            return



        r = x % 10

        if r > 0:

            dq.append(x * 10 + r - 1)

        dq.append(x * 10 + r)

        if r < 9:

            dq.append(x * 10 + r + 1)





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 collections import deque

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


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 +def main(): +    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) +    K = int(eval(input())) +    dq = deque() +    for x in range(1, 10): +        dq.append(x) +    idx = 0 +    while dq: +        x = dq.popleft() +        idx += 1 +        if idx == K: +            print(x) +            return +        r = x % 10 +        if r > 0: +            dq.append(x * 10 + r - 1) +        dq.append(x * 10 + r) +        if r < 9: +            dq.append(x * 10 + r + 1) + + +if __name__ == "__main__": +    main() +# import sys +# +# sys.setrecursionlimit(10 ** 7) +# +# input = sys.stdin.readline +# rstrip() +# int(input()) +# map(int, input().split())