def LunLun(k, count, base):

    nx = []

    n = len(base)

    if count + n >= k:

        ans = base[k - count - 1]

        return ans



    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])



    return LunLun(k, count, nx)





def main():

    k = int(eval(input()))

    base = list(range(1, 10))

    ans = LunLun(k, 0, base)

    print(ans)



if __name__ == '__main__':

    main()

def LunLun(k, count, base):

    nx = []

    n = len(base)

    if count + n >= k:

        ans = base[k - count - 1]

        print(ans)

        exit()



    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])



    return 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:
        ans = base[k - count - 1]
        return ans
    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])
    return LunLun(k, count, nx)


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


if __name__ == "__main__":
    main()

def LunLun(k, count, base):
    nx = []
    n = len(base)
    if count + n >= k:
        ans = base[k - count - 1]
        print(ans)
        exit()
    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])
    return LunLun(k, count, nx)


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


if __name__ == "__main__":
    main()

-        return ans +        print(ans) +        exit() -    ans = LunLun(k, 0, base) -    print(ans) +    LunLun(k, 0, base)