import sys

sys.setrecursionlimit(10**9)



k=int(eval(input()))



def dfs(keta,num):

  lunlun.append(int(num))

  if keta==10:

    return



  min_v=max(0,int(num[-1])-1)

  max_v=min(9,int(num[-1])+1)



  for i in range(min_v,max_v+1):

    dfs(keta+1,num+str(i))



lunlun=[]

for i in range(1,10):

  dfs(0,str(i))



lunlun.sort()

print((lunlun[k-1]))
k=int(eval(input()))



def dfs(keta,num):

  global ans

  ans.append(int(''.join(num)))



  if keta==10:

    return



  min_n=max(0,int(num[-1])-1)

  max_n=min(9,int(num[-1])+1)

  for i in range(min_n,max_n+1):

    dfs(keta+1,num+[str(i)])



ans=[]

for i in range(1,10):

  dfs(1,[str(i)])



ans.sort()

print((ans[k-1]))
import sys

sys.setrecursionlimit(10**9)
k = int(eval(input()))


def dfs(keta, num):
    lunlun.append(int(num))
    if keta == 10:
        return
    min_v = max(0, int(num[-1]) - 1)
    max_v = min(9, int(num[-1]) + 1)
    for i in range(min_v, max_v + 1):
        dfs(keta + 1, num + str(i))


lunlun = []
for i in range(1, 10):
    dfs(0, str(i))
lunlun.sort()
print((lunlun[k - 1]))

k = int(eval(input()))


def dfs(keta, num):
    global ans
    ans.append(int("".join(num)))
    if keta == 10:
        return
    min_n = max(0, int(num[-1]) - 1)
    max_n = min(9, int(num[-1]) + 1)
    for i in range(min_n, max_n + 1):
        dfs(keta + 1, num + [str(i)])


ans = []
for i in range(1, 10):
    dfs(1, [str(i)])
ans.sort()
print((ans[k - 1]))

-import sys - -sys.setrecursionlimit(10**9) -    lunlun.append(int(num)) +    global ans +    ans.append(int("".join(num))) -    min_v = max(0, int(num[-1]) - 1) -    max_v = min(9, int(num[-1]) + 1) -    for i in range(min_v, max_v + 1): -        dfs(keta + 1, num + str(i)) +    min_n = max(0, int(num[-1]) - 1) +    max_n = min(9, int(num[-1]) + 1) +    for i in range(min_n, max_n + 1): +        dfs(keta + 1, num + [str(i)]) -lunlun = [] +ans = [] -    dfs(0, str(i)) -lunlun.sort() -print((lunlun[k - 1])) +    dfs(1, [str(i)]) +ans.sort() +print((ans[k - 1]))