n=int(eval(input()))

if n<10: print(n); exit()

l=[[[] for _ in range(10)] for _ in range(10)]

l[0]=[[i] for i in range(10)]

c=9

for i in range(9):

  for j in range(10):

    for k in (-1,0,1):

      if 0<=j+k<=9:

        for h in l[i][j+k]:

          if j: c+=1

          t=j*10**(i+1)+h

          l[i+1][j]+=[t]

          if c==n: print(t); exit()
n=int(eval(input()))

if n<10: print(n); exit()

r=range

l=[[[] for _ in r(10)] for _ in r(10)]

l[0]=[[i] for i in r(10)]

c=9

for i in r(9):

  for j in r(10):

    for k in r(-1,2):

      if 0<=j+k<=9:

        for h in l[i][j+k]:

          if j: c+=1

          t=j*10**(i+1)+h

          l[i+1][j]+=[t]

          if c==n: print(t); exit()
n = int(eval(input()))
if n < 10:
    print(n)
    exit()
l = [[[] for _ in range(10)] for _ in range(10)]
l[0] = [[i] for i in range(10)]
c = 9
for i in range(9):
    for j in range(10):
        for k in (-1, 0, 1):
            if 0 <= j + k <= 9:
                for h in l[i][j + k]:
                    if j:
                        c += 1
                    t = j * 10 ** (i + 1) + h
                    l[i + 1][j] += [t]
                    if c == n:
                        print(t)
                        exit()

n = int(eval(input()))
if n < 10:
    print(n)
    exit()
r = range
l = [[[] for _ in r(10)] for _ in r(10)]
l[0] = [[i] for i in r(10)]
c = 9
for i in r(9):
    for j in r(10):
        for k in r(-1, 2):
            if 0 <= j + k <= 9:
                for h in l[i][j + k]:
                    if j:
                        c += 1
                    t = j * 10 ** (i + 1) + h
                    l[i + 1][j] += [t]
                    if c == n:
                        print(t)
                        exit()

-l = [[[] for _ in range(10)] for _ in range(10)] -l[0] = [[i] for i in range(10)] +r = range +l = [[[] for _ in r(10)] for _ in r(10)] +l[0] = [[i] for i in r(10)] -for i in range(9): -    for j in range(10): -        for k in (-1, 0, 1): +for i in r(9): +    for j in r(10): +        for k in r(-1, 2):