#!/usr/bin/env python3

import sys, math, itertools, collections, bisect

input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')

inf = float('inf') ;mod = 10**9+7

mans = inf ;ans = 0 ;count = 0 ;pro = 1



sys.setrecursionlimit(10**7)



k = int(eval(input()))

data = [1,2,3,4,5,6,7,8,9]

def dfs(prenum,numberstr):

  if int(numberstr) > 3234566667:return

  if prenum - 1 >= 0:

    data.append(int(numberstr+str(prenum-1)))

    dfs(prenum-1,numberstr+str(prenum-1))

  data.append(int(numberstr+str(prenum)))

  dfs(prenum,numberstr+str(prenum))

  if prenum +1 <= 9:

    data.append(int(numberstr+str(prenum+1)))

    dfs(prenum+1,numberstr+str(prenum+1))

for i in range(1,10):

  dfs(i,str(i))

data.sort()

print((data[k-1]))

# print(data[:20])

# print(len(data))
#!/usr/bin/env python3

import sys, math, itertools, collections, bisect

input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')

inf = float('inf') ;mod = 10**9+7

mans = inf ;ans = 0 ;count = 0 ;pro = 1

sys.setrecursionlimit(10**7)



k = int(eval(input()))

ans = []

def dfs(string):

  if int(string) > 3234566667: return

  ans.append(int(string))

  botom = string[-1]

  intbotom = int(botom)

  if 0 <= intbotom -1 :

    dfs(string + str(intbotom-1))

  dfs(string+botom)

  if intbotom + 1 <= 9:

    dfs(string + str(intbotom+1))

for i in range(1,10):

  dfs(str(i))

ans .sort()



print((ans[k-1]))
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect

input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
sys.setrecursionlimit(10**7)
k = int(eval(input()))
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def dfs(prenum, numberstr):
    if int(numberstr) > 3234566667:
        return
    if prenum - 1 >= 0:
        data.append(int(numberstr + str(prenum - 1)))
        dfs(prenum - 1, numberstr + str(prenum - 1))
    data.append(int(numberstr + str(prenum)))
    dfs(prenum, numberstr + str(prenum))
    if prenum + 1 <= 9:
        data.append(int(numberstr + str(prenum + 1)))
        dfs(prenum + 1, numberstr + str(prenum + 1))


for i in range(1, 10):
    dfs(i, str(i))
data.sort()
print((data[k - 1]))
# print(data[:20])
# print(len(data))

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect

input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
sys.setrecursionlimit(10**7)
k = int(eval(input()))
ans = []


def dfs(string):
    if int(string) > 3234566667:
        return
    ans.append(int(string))
    botom = string[-1]
    intbotom = int(botom)
    if 0 <= intbotom - 1:
        dfs(string + str(intbotom - 1))
    dfs(string + botom)
    if intbotom + 1 <= 9:
        dfs(string + str(intbotom + 1))


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

-data = [1, 2, 3, 4, 5, 6, 7, 8, 9] +ans = [] -def dfs(prenum, numberstr): -    if int(numberstr) > 3234566667: +def dfs(string): +    if int(string) > 3234566667: -    if prenum - 1 >= 0: -        data.append(int(numberstr + str(prenum - 1))) -        dfs(prenum - 1, numberstr + str(prenum - 1)) -    data.append(int(numberstr + str(prenum))) -    dfs(prenum, numberstr + str(prenum)) -    if prenum + 1 <= 9: -        data.append(int(numberstr + str(prenum + 1))) -        dfs(prenum + 1, numberstr + str(prenum + 1)) +    ans.append(int(string)) +    botom = string[-1] +    intbotom = int(botom) +    if 0 <= intbotom - 1: +        dfs(string + str(intbotom - 1)) +    dfs(string + botom) +    if intbotom + 1 <= 9: +        dfs(string + str(intbotom + 1)) -    dfs(i, str(i)) -data.sort() -print((data[k - 1])) -# print(data[:20]) -# print(len(data)) +    dfs(str(i)) +ans.sort() +print((ans[k - 1]))