import collections





def go_next(digits):

    if all(x==9 for x in digits):

        return [0]*len(digits) + [1]



    digits[0] += 1



    maxInc = -1

    # print(digits)

    for i in range(1, len(digits)):

        if digits[i-1] >= 10 or abs(digits[i]-digits[i-1]) >= 2:

            digits[i] += 1

            maxInc = i

        else:

            break

    # print(digits)

    if maxInc > 0:

        for i in range(maxInc, 0, -1):

            digits[i-1] = max(0, digits[i]-1)

    return digits





# go_next([9,8])





def main():

    K = int(eval(input()))



    digits = [0]

    for _ in range(K):

        digits = go_next(digits)



    print(("".join(map(str, reversed(digits)))))





if __name__ == '__main__':

    main()
def main():

    from collections import deque



    K = int(eval(input()))

    q = deque(list(range(1, 10)))

    for _ in range(K):

        x = q.popleft()

        lastdigit = x%10

        base = x*10 + lastdigit

        if lastdigit != 0:

            q.append(base-1)

        q.append(base)

        if lastdigit != 9:

            q.append(base+1)

    print(x)





if __name__ == '__main__':

    main()
import collections


def go_next(digits):
    if all(x == 9 for x in digits):
        return [0] * len(digits) + [1]
    digits[0] += 1
    maxInc = -1
    # print(digits)
    for i in range(1, len(digits)):
        if digits[i - 1] >= 10 or abs(digits[i] - digits[i - 1]) >= 2:
            digits[i] += 1
            maxInc = i
        else:
            break
    # print(digits)
    if maxInc > 0:
        for i in range(maxInc, 0, -1):
            digits[i - 1] = max(0, digits[i] - 1)
    return digits


# go_next([9,8])
def main():
    K = int(eval(input()))
    digits = [0]
    for _ in range(K):
        digits = go_next(digits)
    print(("".join(map(str, reversed(digits)))))


if __name__ == "__main__":
    main()

def main():
    from collections import deque

    K = int(eval(input()))
    q = deque(list(range(1, 10)))
    for _ in range(K):
        x = q.popleft()
        lastdigit = x % 10
        base = x * 10 + lastdigit
        if lastdigit != 0:
            q.append(base - 1)
        q.append(base)
        if lastdigit != 9:
            q.append(base + 1)
    print(x)


if __name__ == "__main__":
    main()

-import collections +def main(): +    from collections import deque - -def go_next(digits): -    if all(x == 9 for x in digits): -        return [0] * len(digits) + [1] -    digits[0] += 1 -    maxInc = -1 -    # print(digits) -    for i in range(1, len(digits)): -        if digits[i - 1] >= 10 or abs(digits[i] - digits[i - 1]) >= 2: -            digits[i] += 1 -            maxInc = i -        else: -            break -    # print(digits) -    if maxInc > 0: -        for i in range(maxInc, 0, -1): -            digits[i - 1] = max(0, digits[i] - 1) -    return digits - - -# go_next([9,8]) -def main(): -    digits = [0] +    q = deque(list(range(1, 10))) -        digits = go_next(digits) -    print(("".join(map(str, reversed(digits))))) +        x = q.popleft() +        lastdigit = x % 10 +        base = x * 10 + lastdigit +        if lastdigit != 0: +            q.append(base - 1) +        q.append(base) +        if lastdigit != 9: +            q.append(base + 1) +    print(x)