n=int(eval(input()))

if n<=10 : 

  print(n)

  exit()

  

ans=[0 for i in range(10**5+21)]

Q=[0,1,2,3]

def li(x):

  if x==0 : return [0,1]

  if x==9 : return [8,9]

  return [x-1,x,x+1]



now=0

for q in Q:

  W=[i for i in range(10)] if q==0 else li(q)

  for w in W:

    E=[i for i in range(10)] if [q,w]==[0,0] else li(w)

    for e in E:

      R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)

      for r in R:

        T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)

        for t in T:

          Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)

          for y in Y:

            U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)

            for u in U:

              I=[i for i in range(10)] if [q,w,e,r,t,y,u]==[0,0,0,0,0,0,0] else li(u)

              for i in I:

                O=[i for i in range(10)] if [q,w,e,r,t,y,u,i]==[0,0,0,0,0,0,0,0] else li(i)

                for o in O:

                  P=[i for i in range(10)] if [q,w,e,r,t,y,u,i,o]==[0,0,0,0,0,0,0,0,0,0] else li(o)

                  for p in P:

                    

                    ans[now]= 10**9*q + 10**8*w + 10**7*e + 10**6*r + 10**5*t + 10**4*y + 1000*u + 100*i + 10*o + p

                    

                    if now>=10**5+2 : break

                    now+=1



ans=list(set(ans))

n-=8

ans.sort()

print((ans[n]))
n=int(eval(input()))

ans=[0 for i in range(10**5+21)]

Q=[0,1,2,3]

def li(x):

  if x==0 : return [0,1]

  if x==9 : return [8,9]

  return [x-1,x,x+1]



now=0

for q in Q:

  W=[i for i in range(10)] if q==0 else li(q)

  for w in W:

    E=[i for i in range(10)] if [q,w]==[0,0] else li(w)

    for e in E:

      R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)

      for r in R:

        T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)

        for t in T:

          Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)

          for y in Y:

            U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)

            for u in U:

              I=[i for i in range(10)] if [q,w,e,r,t,y,u]==[0,0,0,0,0,0,0] else li(u)

              for i in I:

                O=[i for i in range(10)] if [q,w,e,r,t,y,u,i]==[0,0,0,0,0,0,0,0] else li(i)

                for o in O:

                  P=[i for i in range(10)] if [q,w,e,r,t,y,u,i,o]==[0,0,0,0,0,0,0,0,0] else li(o)

                  for p in P:

                    

                    ans[now]= 10**9*q + 10**8*w + 10**7*e + 10**6*r + 10**5*t + 10**4*y + 1000*u + 100*i + 10*o + p

                    

                    if now>=10**5+2 : break

                    now+=1





print((ans[n]))
n = int(eval(input()))
if n <= 10:
    print(n)
    exit()
ans = [0 for i in range(10**5 + 21)]
Q = [0, 1, 2, 3]


def li(x):
    if x == 0:
        return [0, 1]
    if x == 9:
        return [8, 9]
    return [x - 1, x, x + 1]


now = 0
for q in Q:
    W = [i for i in range(10)] if q == 0 else li(q)
    for w in W:
        E = [i for i in range(10)] if [q, w] == [0, 0] else li(w)
        for e in E:
            R = [i for i in range(10)] if [q, w, e] == [0, 0, 0] else li(e)
            for r in R:
                T = [i for i in range(10)] if [q, w, r, e] == [0, 0, 0, 0] else li(r)
                for t in T:
                    Y = (
                        [i for i in range(10)]
                        if [q, w, e, r, t] == [0, 0, 0, 0, 0]
                        else li(t)
                    )
                    for y in Y:
                        U = (
                            [i for i in range(10)]
                            if [q, w, e, r, t, y] == [0, 0, 0, 0, 0, 0]
                            else li(y)
                        )
                        for u in U:
                            I = (
                                [i for i in range(10)]
                                if [q, w, e, r, t, y, u] == [0, 0, 0, 0, 0, 0, 0]
                                else li(u)
                            )
                            for i in I:
                                O = (
                                    [i for i in range(10)]
                                    if [q, w, e, r, t, y, u, i]
                                    == [0, 0, 0, 0, 0, 0, 0, 0]
                                    else li(i)
                                )
                                for o in O:
                                    P = (
                                        [i for i in range(10)]
                                        if [q, w, e, r, t, y, u, i, o]
                                        == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                                        else li(o)
                                    )
                                    for p in P:
                                        ans[now] = (
                                            10**9 * q
                                            + 10**8 * w
                                            + 10**7 * e
                                            + 10**6 * r
                                            + 10**5 * t
                                            + 10**4 * y
                                            + 1000 * u
                                            + 100 * i
                                            + 10 * o
                                            + p
                                        )
                                        if now >= 10**5 + 2:
                                            break
                                        now += 1
ans = list(set(ans))
n -= 8
ans.sort()
print((ans[n]))

n = int(eval(input()))
ans = [0 for i in range(10**5 + 21)]
Q = [0, 1, 2, 3]


def li(x):
    if x == 0:
        return [0, 1]
    if x == 9:
        return [8, 9]
    return [x - 1, x, x + 1]


now = 0
for q in Q:
    W = [i for i in range(10)] if q == 0 else li(q)
    for w in W:
        E = [i for i in range(10)] if [q, w] == [0, 0] else li(w)
        for e in E:
            R = [i for i in range(10)] if [q, w, e] == [0, 0, 0] else li(e)
            for r in R:
                T = [i for i in range(10)] if [q, w, r, e] == [0, 0, 0, 0] else li(r)
                for t in T:
                    Y = (
                        [i for i in range(10)]
                        if [q, w, e, r, t] == [0, 0, 0, 0, 0]
                        else li(t)
                    )
                    for y in Y:
                        U = (
                            [i for i in range(10)]
                            if [q, w, e, r, t, y] == [0, 0, 0, 0, 0, 0]
                            else li(y)
                        )
                        for u in U:
                            I = (
                                [i for i in range(10)]
                                if [q, w, e, r, t, y, u] == [0, 0, 0, 0, 0, 0, 0]
                                else li(u)
                            )
                            for i in I:
                                O = (
                                    [i for i in range(10)]
                                    if [q, w, e, r, t, y, u, i]
                                    == [0, 0, 0, 0, 0, 0, 0, 0]
                                    else li(i)
                                )
                                for o in O:
                                    P = (
                                        [i for i in range(10)]
                                        if [q, w, e, r, t, y, u, i, o]
                                        == [0, 0, 0, 0, 0, 0, 0, 0, 0]
                                        else li(o)
                                    )
                                    for p in P:
                                        ans[now] = (
                                            10**9 * q
                                            + 10**8 * w
                                            + 10**7 * e
                                            + 10**6 * r
                                            + 10**5 * t
                                            + 10**4 * y
                                            + 1000 * u
                                            + 100 * i
                                            + 10 * o
                                            + p
                                        )
                                        if now >= 10**5 + 2:
                                            break
                                        now += 1
print((ans[n]))

-if n <= 10: -    print(n) -    exit() -                                        == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] +                                        == [0, 0, 0, 0, 0, 0, 0, 0, 0] -ans = list(set(ans)) -n -= 8 -ans.sort()