import sys

sys.setrecursionlimit(10**7)

k = int(eval(input()))

from collections import deque

d = deque()

for i in range(9):

    d.append(str(i+1)) # 初期



def dfs():

    global cnt

    a = d.popleft()

    

    #print(cnt)

    for i in range(-1,2,1):

        nya = a

        last_string = int(a[-1]) + i

        if last_string < 0 or last_string > 9:

            pass

        else:

            nya += str(last_string)

            cnt += 1

            if k == cnt:

                print(nya)

                exit()

            d.append(nya)

    dfs()



cnt = 9

if k <= cnt:

    print(k)

    exit()

dfs()

from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

from fractions import gcd

from itertools import combinations # (string,3) 3回

from collections import deque

from collections import defaultdict

import bisect

#

#    d = m - k[i] - k[j]

#    if kk[bisect.bisect_right(kk,d) - 1] == d:

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#



import sys

sys.setrecursionlimit(10000000)

mod = 10**9 + 7



def readInts():

  return list(map(int,input().split()))

def I():

  return int(eval(input()))

k = I()

que = deque([])

for i in range(1,10):

    que.append(i)

if k <= 9:

    print((que[k-1]))

    exit()

while que:

    num = que.popleft()

    if k == 1:

        print(num)

        exit()

    lo = num%10

    if 0 <= lo - 1:

        que.append(num*10 + lo-1)

    que.append(num*10 + lo)

    if lo + 1 <= 9:

        que.append(num*10 + lo + 1)

    k -= 1

import sys

sys.setrecursionlimit(10**7)
k = int(eval(input()))
from collections import deque

d = deque()
for i in range(9):
    d.append(str(i + 1))  # 初期


def dfs():
    global cnt
    a = d.popleft()
    # print(cnt)
    for i in range(-1, 2, 1):
        nya = a
        last_string = int(a[-1]) + i
        if last_string < 0 or last_string > 9:
            pass
        else:
            nya += str(last_string)
            cnt += 1
            if k == cnt:
                print(nya)
                exit()
            d.append(nya)
    dfs()


cnt = 9
if k <= cnt:
    print(k)
    exit()
dfs()

from statistics import median

# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations  # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect

#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
import sys

sys.setrecursionlimit(10000000)
mod = 10**9 + 7


def readInts():
    return list(map(int, input().split()))


def I():
    return int(eval(input()))


k = I()
que = deque([])
for i in range(1, 10):
    que.append(i)
if k <= 9:
    print((que[k - 1]))
    exit()
while que:
    num = que.popleft()
    if k == 1:
        print(num)
        exit()
    lo = num % 10
    if 0 <= lo - 1:
        que.append(num * 10 + lo - 1)
    que.append(num * 10 + lo)
    if lo + 1 <= 9:
        que.append(num * 10 + lo + 1)
    k -= 1

+from statistics import median + +# import collections +# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] +from fractions import gcd +from itertools import combinations  # (string,3) 3回 +from collections import deque +from collections import defaultdict +import bisect + +# +#    d = m - k[i] - k[j] +#    if kk[bisect.bisect_right(kk,d) - 1] == d: +# +# +# +# pythonで無理なときは、pypyでやると正解するかも！！ +# +# -sys.setrecursionlimit(10**7) -k = int(eval(input())) -from collections import deque - -d = deque() -for i in range(9): -    d.append(str(i + 1))  # 初期 +sys.setrecursionlimit(10000000) +mod = 10**9 + 7 -def dfs(): -    global cnt -    a = d.popleft() -    # print(cnt) -    for i in range(-1, 2, 1): -        nya = a -        last_string = int(a[-1]) + i -        if last_string < 0 or last_string > 9: -            pass -        else: -            nya += str(last_string) -            cnt += 1 -            if k == cnt: -                print(nya) -                exit() -            d.append(nya) -    dfs() +def readInts(): +    return list(map(int, input().split())) -cnt = 9 -if k <= cnt: -    print(k) +def I(): +    return int(eval(input())) + + +k = I() +que = deque([]) +for i in range(1, 10): +    que.append(i) +if k <= 9: +    print((que[k - 1])) -dfs() +while que: +    num = que.popleft() +    if k == 1: +        print(num) +        exit() +    lo = num % 10 +    if 0 <= lo - 1: +        que.append(num * 10 + lo - 1) +    que.append(num * 10 + lo) +    if lo + 1 <= 9: +        que.append(num * 10 + lo + 1) +    k -= 1