def main():

    from collections import deque

    k = int(eval(input()))

    ans = 0

    que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

    x = 0

    for _ in range(k):

        x = que.popleft()



        p = x % 10

        e = 10 * x

        if p != 0:

            a = e + p - 1

            que.append(a)

        b = e + p

        que.append(b)

        if p != 9:

            c = e + p + 1

            que.append(c)

    print(x)





if __name__ == '__main__':

    main()

def LunLun(k, count, base):

    nx = []

    n = len(base)

    if count + n >= k:

        print((base[k - count - 1]))

        return

    for x in base:

        count += 1

        p = x % 10

        x *= 10

        a = x + p - 1

        b = a + 1

        c = b + 1

        n = 3

        if p == 0:

            n -= 1

            nx.extend([b, c])

        elif p == 9:

            n -= 1

            nx.extend([a, b])

        else:

            nx.extend([a, b, c])



    LunLun(k, count, nx)





def main():

    k = int(eval(input()))

    base = list(range(1, 10))

    LunLun(k, 0, base)





if __name__ == '__main__':

    main()

def main():
    from collections import deque

    k = int(eval(input()))
    ans = 0
    que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    x = 0
    for _ in range(k):
        x = que.popleft()
        p = x % 10
        e = 10 * x
        if p != 0:
            a = e + p - 1
            que.append(a)
        b = e + p
        que.append(b)
        if p != 9:
            c = e + p + 1
            que.append(c)
    print(x)


if __name__ == "__main__":
    main()

def LunLun(k, count, base):
    nx = []
    n = len(base)
    if count + n >= k:
        print((base[k - count - 1]))
        return
    for x in base:
        count += 1
        p = x % 10
        x *= 10
        a = x + p - 1
        b = a + 1
        c = b + 1
        n = 3
        if p == 0:
            n -= 1
            nx.extend([b, c])
        elif p == 9:
            n -= 1
            nx.extend([a, b])
        else:
            nx.extend([a, b, c])
    LunLun(k, count, nx)


def main():
    k = int(eval(input()))
    base = list(range(1, 10))
    LunLun(k, 0, base)


if __name__ == "__main__":
    main()

+def LunLun(k, count, base): +    nx = [] +    n = len(base) +    if count + n >= k: +        print((base[k - count - 1])) +        return +    for x in base: +        count += 1 +        p = x % 10 +        x *= 10 +        a = x + p - 1 +        b = a + 1 +        c = b + 1 +        n = 3 +        if p == 0: +            n -= 1 +            nx.extend([b, c]) +        elif p == 9: +            n -= 1 +            nx.extend([a, b]) +        else: +            nx.extend([a, b, c]) +    LunLun(k, count, nx) + + -    from collections import deque - -    ans = 0 -    que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -    x = 0 -    for _ in range(k): -        x = que.popleft() -        p = x % 10 -        e = 10 * x -        if p != 0: -            a = e + p - 1 -            que.append(a) -        b = e + p -        que.append(b) -        if p != 9: -            c = e + p + 1 -            que.append(c) -    print(x) +    base = list(range(1, 10)) +    LunLun(k, 0, base)