from collections import deque

def main():

    q=deque()

    for i in range(1,10):

        q.append((str(i)))

    Ans=[]

    while q:

        s=q.popleft()

        if int(s)>3234566667:

            continue

        Ans.append(int(s))

        d=int(s[-1])

        if d==0:

            q.append(s+'0')

            q.append(s+'1')

        elif d==9:

            q.append(s+'8')

            q.append(s+'9')

        else:

            V=[d-1,d,d+1]

            for v in V:

                q.append(s+str(v))

    Ans.sort()

    #print(len(Ans))

    k=int(eval(input()))

    print((Ans[k-1]))

    

if __name__=='__main__':

    main()
from collections import deque

def main():

    k=int(eval(input()))

    if k<=9:

        return k

    q=deque()

    for i in range(1,10):

        q.append(i)

    Ans=list(range(1,10))

    cnt=9

    while cnt<k:

        s=q.popleft()

        d=s%10

        s*=10

        if d==0:

            q.append(s)

            q.append(s+1)

            Ans.append(s)

            Ans.append(s+1)

            cnt+=2

        elif d==9:

            q.append(s+8)

            q.append(s+9)

            Ans.append(s+8)

            Ans.append(s+9)

            cnt+=2

        else:

            V=[d-1,d,d+1]

            for v in V:

                q.append(s+v)

                Ans.append(s+v)

            cnt+=3

    return Ans[k-1]

    

if __name__=='__main__':

    print((main()))
from collections import deque


def main():
    q = deque()
    for i in range(1, 10):
        q.append((str(i)))
    Ans = []
    while q:
        s = q.popleft()
        if int(s) > 3234566667:
            continue
        Ans.append(int(s))
        d = int(s[-1])
        if d == 0:
            q.append(s + "0")
            q.append(s + "1")
        elif d == 9:
            q.append(s + "8")
            q.append(s + "9")
        else:
            V = [d - 1, d, d + 1]
            for v in V:
                q.append(s + str(v))
    Ans.sort()
    # print(len(Ans))
    k = int(eval(input()))
    print((Ans[k - 1]))


if __name__ == "__main__":
    main()

from collections import deque


def main():
    k = int(eval(input()))
    if k <= 9:
        return k
    q = deque()
    for i in range(1, 10):
        q.append(i)
    Ans = list(range(1, 10))
    cnt = 9
    while cnt < k:
        s = q.popleft()
        d = s % 10
        s *= 10
        if d == 0:
            q.append(s)
            q.append(s + 1)
            Ans.append(s)
            Ans.append(s + 1)
            cnt += 2
        elif d == 9:
            q.append(s + 8)
            q.append(s + 9)
            Ans.append(s + 8)
            Ans.append(s + 9)
            cnt += 2
        else:
            V = [d - 1, d, d + 1]
            for v in V:
                q.append(s + v)
                Ans.append(s + v)
            cnt += 3
    return Ans[k - 1]


if __name__ == "__main__":
    print((main()))

+    k = int(eval(input())) +    if k <= 9: +        return k -        q.append((str(i))) -    Ans = [] -    while q: +        q.append(i) +    Ans = list(range(1, 10)) +    cnt = 9 +    while cnt < k: -        if int(s) > 3234566667: -            continue -        Ans.append(int(s)) -        d = int(s[-1]) +        d = s % 10 +        s *= 10 -            q.append(s + "0") -            q.append(s + "1") +            q.append(s) +            q.append(s + 1) +            Ans.append(s) +            Ans.append(s + 1) +            cnt += 2 -            q.append(s + "8") -            q.append(s + "9") +            q.append(s + 8) +            q.append(s + 9) +            Ans.append(s + 8) +            Ans.append(s + 9) +            cnt += 2 -                q.append(s + str(v)) -    Ans.sort() -    # print(len(Ans)) -    k = int(eval(input())) -    print((Ans[k - 1])) +                q.append(s + v) +                Ans.append(s + v) +            cnt += 3 +    return Ans[k - 1] -    main() +    print((main()))