def main():

    k = int(eval(input()))

    hp = list(range(1, 10))

    for i in range(k-1):

        n = hp.pop(0)

        nm = n % 10

        val = n * 10 + nm

        

        if nm != 0:

            hp.append(val - 1)

        hp.append(val)

        if nm != 9:

            hp.append(val + 1)

    print((hp[0]))



main()

def main():

    k = int(eval(input()))

    hp = [i for i in range(k+4)]

    r, w = 1, 10

    while w <= k:

        n = hp[r]

        r += 1

        nm = n % 10

        val = n * 10 + nm

        

        if nm != 0:

            hp[w] = val - 1

            w += 1

        hp[w] = val

        w += 1

        if nm != 9:

            hp[w] = val + 1

            w += 1



    print((hp[k]))



main()

def main():
    k = int(eval(input()))
    hp = list(range(1, 10))
    for i in range(k - 1):
        n = hp.pop(0)
        nm = n % 10
        val = n * 10 + nm
        if nm != 0:
            hp.append(val - 1)
        hp.append(val)
        if nm != 9:
            hp.append(val + 1)
    print((hp[0]))


main()

def main():
    k = int(eval(input()))
    hp = [i for i in range(k + 4)]
    r, w = 1, 10
    while w <= k:
        n = hp[r]
        r += 1
        nm = n % 10
        val = n * 10 + nm
        if nm != 0:
            hp[w] = val - 1
            w += 1
        hp[w] = val
        w += 1
        if nm != 9:
            hp[w] = val + 1
            w += 1
    print((hp[k]))


main()

-    hp = list(range(1, 10)) -    for i in range(k - 1): -        n = hp.pop(0) +    hp = [i for i in range(k + 4)] +    r, w = 1, 10 +    while w <= k: +        n = hp[r] +        r += 1 -            hp.append(val - 1) -        hp.append(val) +            hp[w] = val - 1 +            w += 1 +        hp[w] = val +        w += 1 -            hp.append(val + 1) -    print((hp[0])) +            hp[w] = val + 1 +            w += 1 +    print((hp[k]))