k = int(eval(input()))



A = [i for i in range(1, 10)]



while k:

    if k <= len(A):

        print((A[k-1]))

        exit()



    k -= len(A)

    

    old = []

    old, A = A, old

    for x in old:

        for i in range(-1, 2):

          d = (x % 10) + i

          if d < 0 or d > 9: continue

            

          nx = (x * 10) + d

          A.append(nx)
k = int(eval(input()))



RunRun = [i for i in range(1, 10)]



while True:

    if k <= len(RunRun):

        print((RunRun[k-1]))

        exit()

        

    k -= len(RunRun)

    

    now = []

    now, RunRun = RunRun, now



    for r in now:

        for i in range(-1, 2):

            tmp = r % 10 + i

            if tmp < 0 or 9 < tmp: continue

            tmp = (r * 10) + tmp

            RunRun.append(tmp)

        #print(RunRun)

k = int(eval(input()))
A = [i for i in range(1, 10)]
while k:
    if k <= len(A):
        print((A[k - 1]))
        exit()
    k -= len(A)
    old = []
    old, A = A, old
    for x in old:
        for i in range(-1, 2):
            d = (x % 10) + i
            if d < 0 or d > 9:
                continue
            nx = (x * 10) + d
            A.append(nx)

k = int(eval(input()))
RunRun = [i for i in range(1, 10)]
while True:
    if k <= len(RunRun):
        print((RunRun[k - 1]))
        exit()
    k -= len(RunRun)
    now = []
    now, RunRun = RunRun, now
    for r in now:
        for i in range(-1, 2):
            tmp = r % 10 + i
            if tmp < 0 or 9 < tmp:
                continue
            tmp = (r * 10) + tmp
            RunRun.append(tmp)
        # print(RunRun)

-A = [i for i in range(1, 10)] -while k: -    if k <= len(A): -        print((A[k - 1])) +RunRun = [i for i in range(1, 10)] +while True: +    if k <= len(RunRun): +        print((RunRun[k - 1])) -    k -= len(A) -    old = [] -    old, A = A, old -    for x in old: +    k -= len(RunRun) +    now = [] +    now, RunRun = RunRun, now +    for r in now: -            d = (x % 10) + i -            if d < 0 or d > 9: +            tmp = r % 10 + i +            if tmp < 0 or 9 < tmp: -            nx = (x * 10) + d -            A.append(nx) +            tmp = (r * 10) + tmp +            RunRun.append(tmp) +        # print(RunRun)