k=int(eval(input()))



a=[]

for i in range(1,10):

    a.append(i)

while True:

    if k<=len(a):

        print((a[k-1]))

        break

    

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



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



for x in a:

    if k<=len(a):

        break

    

    if x%10!=0:

        a.append(10*x+(x%10)-1)

    a.append(10*x+(x%10))

    if x%10!=9:

        a.append(10*x+(x%10)+1)

        

print((a[k-1]))
k = int(eval(input()))
a = []
for i in range(1, 10):
    a.append(i)
while True:
    if k <= len(a):
        print((a[k - 1]))
        break
    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()))
a = [i for i in range(1, 10)]
for x in a:
    if k <= len(a):
        break
    if x % 10 != 0:
        a.append(10 * x + (x % 10) - 1)
    a.append(10 * x + (x % 10))
    if x % 10 != 9:
        a.append(10 * x + (x % 10) + 1)
print((a[k - 1]))

-a = [] -for i in range(1, 10): -    a.append(i) -while True: +a = [i for i in range(1, 10)] +for x in a: -        print((a[k - 1])) -    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) +    if x % 10 != 0: +        a.append(10 * x + (x % 10) - 1) +    a.append(10 * x + (x % 10)) +    if x % 10 != 9: +        a.append(10 * x + (x % 10) + 1) +print((a[k - 1]))