k=int(eval(input()))

l=[]

for i1 in range(10):

  l.append(i1)

  for i2 in range(max(i1-1,0),min(i1+2,10)):

    l.append(i1*(10**1)+i2)

    for i3 in range(max(i2-1,0),min(i2+2,10)):

      l.append(i1*(10**2)+i2*(10**1)+i3)

      for i4 in range(max(i3-1,0),min(i3+2,10)):

        l.append(i1*(10**3)+i2*(10**2)+i3*(10**1)+i4)

        for i5 in range(max(i4-1,0),min(i4+2,10)):

          l.append(i1*(10**4)+i2*(10**3)+i3*(10**2)+i4*(10**1)+i5)

          for i6 in range(max(i5-1,0),min(i5+2,10)):

            l.append(i1*(10**5)+i2*(10**4)+i3*(10**3)+i4*(10**2)+i5*(10**1)+i6)

            for i7 in range(max(i6-1,0),min(i6+2,10)):

              l.append(i1*(10**6)+i2*(10**5)+i3*(10**4)+i4*(10**3)+i5*(10**2)+i6*(10**1)+i7)

              for i8 in range(max(i7-1,0),min(i7+2,10)):

                l.append(i1*(10**7)+i2*(10**6)+i3*(10**5)+i4*(10**4)+i5*(10**3)+i6*(10**2)+i7*(10**1)+i8)

                for i9 in range(max(i8-1,0),min(i8+2,10)):

                  l.append(i1*(10**8)+i2*(10**7)+i3*(10**6)+i4*(10**5)+i5*(10**4)+i6*(10**3)+i7*(10**2)+i8*(10**1)+i9)

                  for i10 in range(max(i9-1,0),min(i9+2,10)):

                    l.append(i1*(10**9)+i2*(10**8)+i3*(10**7)+i4*(10**6)+i5*(10**5)+i6*(10**4)+i7*(10**3)+i8*(10**2)+i9*(10**1)+i10)



l=list(set(l))

l.sort()

print((l[k]))
import copy

k=int(eval(input()))

ans=[[str(i+1) for i in range(9)]]

l2=[]

for i in range(9):

  l=ans[-1]

  l2=[]

  for j in range(len(l)):

    if int(l[j][-1])!=0:

      l2.append(l[j]+str(int(l[j][-1])-1))

    l2.append(l[j]+str(int(l[j][-1])))

    if int(l[j][-1])!=9:

      l2.append(l[j]+str(int(l[j][-1])+1))

  ans.append(l2)

  l=copy.copy(l2)

a=[]

for i in range(10):

  a=a+ans[i]

print((a[k-1]))
k = int(eval(input()))
l = []
for i1 in range(10):
    l.append(i1)
    for i2 in range(max(i1 - 1, 0), min(i1 + 2, 10)):
        l.append(i1 * (10**1) + i2)
        for i3 in range(max(i2 - 1, 0), min(i2 + 2, 10)):
            l.append(i1 * (10**2) + i2 * (10**1) + i3)
            for i4 in range(max(i3 - 1, 0), min(i3 + 2, 10)):
                l.append(i1 * (10**3) + i2 * (10**2) + i3 * (10**1) + i4)
                for i5 in range(max(i4 - 1, 0), min(i4 + 2, 10)):
                    l.append(
                        i1 * (10**4)
                        + i2 * (10**3)
                        + i3 * (10**2)
                        + i4 * (10**1)
                        + i5
                    )
                    for i6 in range(max(i5 - 1, 0), min(i5 + 2, 10)):
                        l.append(
                            i1 * (10**5)
                            + i2 * (10**4)
                            + i3 * (10**3)
                            + i4 * (10**2)
                            + i5 * (10**1)
                            + i6
                        )
                        for i7 in range(max(i6 - 1, 0), min(i6 + 2, 10)):
                            l.append(
                                i1 * (10**6)
                                + i2 * (10**5)
                                + i3 * (10**4)
                                + i4 * (10**3)
                                + i5 * (10**2)
                                + i6 * (10**1)
                                + i7
                            )
                            for i8 in range(max(i7 - 1, 0), min(i7 + 2, 10)):
                                l.append(
                                    i1 * (10**7)
                                    + i2 * (10**6)
                                    + i3 * (10**5)
                                    + i4 * (10**4)
                                    + i5 * (10**3)
                                    + i6 * (10**2)
                                    + i7 * (10**1)
                                    + i8
                                )
                                for i9 in range(max(i8 - 1, 0), min(i8 + 2, 10)):
                                    l.append(
                                        i1 * (10**8)
                                        + i2 * (10**7)
                                        + i3 * (10**6)
                                        + i4 * (10**5)
                                        + i5 * (10**4)
                                        + i6 * (10**3)
                                        + i7 * (10**2)
                                        + i8 * (10**1)
                                        + i9
                                    )
                                    for i10 in range(max(i9 - 1, 0), min(i9 + 2, 10)):
                                        l.append(
                                            i1 * (10**9)
                                            + i2 * (10**8)
                                            + i3 * (10**7)
                                            + i4 * (10**6)
                                            + i5 * (10**5)
                                            + i6 * (10**4)
                                            + i7 * (10**3)
                                            + i8 * (10**2)
                                            + i9 * (10**1)
                                            + i10
                                        )
l = list(set(l))
l.sort()
print((l[k]))

import copy

k = int(eval(input()))
ans = [[str(i + 1) for i in range(9)]]
l2 = []
for i in range(9):
    l = ans[-1]
    l2 = []
    for j in range(len(l)):
        if int(l[j][-1]) != 0:
            l2.append(l[j] + str(int(l[j][-1]) - 1))
        l2.append(l[j] + str(int(l[j][-1])))
        if int(l[j][-1]) != 9:
            l2.append(l[j] + str(int(l[j][-1]) + 1))
    ans.append(l2)
    l = copy.copy(l2)
a = []
for i in range(10):
    a = a + ans[i]
print((a[k - 1]))

+import copy + -l = [] -for i1 in range(10): -    l.append(i1) -    for i2 in range(max(i1 - 1, 0), min(i1 + 2, 10)): -        l.append(i1 * (10**1) + i2) -        for i3 in range(max(i2 - 1, 0), min(i2 + 2, 10)): -            l.append(i1 * (10**2) + i2 * (10**1) + i3) -            for i4 in range(max(i3 - 1, 0), min(i3 + 2, 10)): -                l.append(i1 * (10**3) + i2 * (10**2) + i3 * (10**1) + i4) -                for i5 in range(max(i4 - 1, 0), min(i4 + 2, 10)): -                    l.append( -                        i1 * (10**4) -                        + i2 * (10**3) -                        + i3 * (10**2) -                        + i4 * (10**1) -                        + i5 -                    ) -                    for i6 in range(max(i5 - 1, 0), min(i5 + 2, 10)): -                        l.append( -                            i1 * (10**5) -                            + i2 * (10**4) -                            + i3 * (10**3) -                            + i4 * (10**2) -                            + i5 * (10**1) -                            + i6 -                        ) -                        for i7 in range(max(i6 - 1, 0), min(i6 + 2, 10)): -                            l.append( -                                i1 * (10**6) -                                + i2 * (10**5) -                                + i3 * (10**4) -                                + i4 * (10**3) -                                + i5 * (10**2) -                                + i6 * (10**1) -                                + i7 -                            ) -                            for i8 in range(max(i7 - 1, 0), min(i7 + 2, 10)): -                                l.append( -                                    i1 * (10**7) -                                    + i2 * (10**6) -                                    + i3 * (10**5) -                                    + i4 * (10**4) -                                    + i5 * (10**3) -                                    + i6 * (10**2) -                                    + i7 * (10**1) -                                    + i8 -                                ) -                                for i9 in range(max(i8 - 1, 0), min(i8 + 2, 10)): -                                    l.append( -                                        i1 * (10**8) -                                        + i2 * (10**7) -                                        + i3 * (10**6) -                                        + i4 * (10**5) -                                        + i5 * (10**4) -                                        + i6 * (10**3) -                                        + i7 * (10**2) -                                        + i8 * (10**1) -                                        + i9 -                                    ) -                                    for i10 in range(max(i9 - 1, 0), min(i9 + 2, 10)): -                                        l.append( -                                            i1 * (10**9) -                                            + i2 * (10**8) -                                            + i3 * (10**7) -                                            + i4 * (10**6) -                                            + i5 * (10**5) -                                            + i6 * (10**4) -                                            + i7 * (10**3) -                                            + i8 * (10**2) -                                            + i9 * (10**1) -                                            + i10 -                                        ) -l = list(set(l)) -l.sort() -print((l[k])) +ans = [[str(i + 1) for i in range(9)]] +l2 = [] +for i in range(9): +    l = ans[-1] +    l2 = [] +    for j in range(len(l)): +        if int(l[j][-1]) != 0: +            l2.append(l[j] + str(int(l[j][-1]) - 1)) +        l2.append(l[j] + str(int(l[j][-1]))) +        if int(l[j][-1]) != 9: +            l2.append(l[j] + str(int(l[j][-1]) + 1)) +    ans.append(l2) +    l = copy.copy(l2) +a = [] +for i in range(10): +    a = a + ans[i] +print((a[k - 1]))