import collections

m = int(eval(input()))

n = 1000000000

ans = []

listnum = [

            [0, 1],

            [0, 1, 2],

            [1, 2, 3],

            [2, 3, 4],

            [3, 4, 5],

            [4, 5, 6],

            [5, 6, 7],

            [6, 7, 8],

            [7, 8, 9],

            [8, 9]

           ]

def dfs(s):

    if len(str(n)) + 1 > len(s):

        ans.append(int(s))

        lastnum = str(s)[-1]

        for i in listnum[int(lastnum)]:

            dfs(s + str(i))

for i in range(1, 10):

    dfs(str(i))

ans = sorted(ans)

print((ans[m - 1]))
def getN():

    return int(eval(input()))

def getNM():

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

def getList():

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

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)



def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)



from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

import math

from fractions import gcd

import random

import string

import copy

from itertools import permutations

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7





#############

# Main Code #

#############



N = getN()



next = [

[0, 1],

[0, 1, 2],

[1, 2, 3],

[2, 3, 4],

[3, 4, 5],

[4, 5, 6],

[5, 6, 7],

[6, 7, 8],

[7, 8, 9],

[8, 9]

]



ans = []



def dfs(s):

    global ans

    if len(s) >= 11:

        return

    # 上限を超えない範囲で実行

    else:

        ans.append(int(s))

        # dfs

        s_last = int(s[-1])

        for i in next[s_last]:

            dfs(s + str(i))



# 始点は1~9

for i in range(1, 10):

    dfs(str(i))



ans.sort()

print((ans[N - 1]))
import collections

m = int(eval(input()))
n = 1000000000
ans = []
listnum = [
    [0, 1],
    [0, 1, 2],
    [1, 2, 3],
    [2, 3, 4],
    [3, 4, 5],
    [4, 5, 6],
    [5, 6, 7],
    [6, 7, 8],
    [7, 8, 9],
    [8, 9],
]


def dfs(s):
    if len(str(n)) + 1 > len(s):
        ans.append(int(s))
        lastnum = str(s)[-1]
        for i in listnum[int(lastnum)]:
            dfs(s + str(i))


for i in range(1, 10):
    dfs(str(i))
ans = sorted(ans)
print((ans[m - 1]))

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


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


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


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


def input():
    return sys.stdin.readline().rstrip()


def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)


def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]


def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)


def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)


from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N = getN()
next = [
    [0, 1],
    [0, 1, 2],
    [1, 2, 3],
    [2, 3, 4],
    [3, 4, 5],
    [4, 5, 6],
    [5, 6, 7],
    [6, 7, 8],
    [7, 8, 9],
    [8, 9],
]
ans = []


def dfs(s):
    global ans
    if len(s) >= 11:
        return
    # 上限を超えない範囲で実行
    else:
        ans.append(int(s))
        # dfs
        s_last = int(s[-1])
        for i in next[s_last]:
            dfs(s + str(i))


# 始点は1~9
for i in range(1, 10):
    dfs(str(i))
ans.sort()
print((ans[N - 1]))

-import collections +def getN(): +    return int(eval(input())) -m = int(eval(input())) -n = 1000000000 -ans = [] -listnum = [ + +def getNM(): +    return list(map(int, input().split())) + + +def getList(): +    return list(map(int, input().split())) + + +def getArray(intn): +    return [int(eval(input())) for i in range(intn)] + + +def input(): +    return sys.stdin.readline().rstrip() + + +def rand_N(ran1, ran2): +    return random.randint(ran1, ran2) + + +def rand_List(ran1, ran2, rantime): +    return [random.randint(ran1, ran2) for i in range(rantime)] + + +def rand_ints_nodup(ran1, ran2, rantime): +    ns = [] +    while len(ns) < rantime: +        n = random.randint(ran1, ran2) +        if not n in ns: +            ns.append(n) +    return sorted(ns) + + +def rand_query(ran1, ran2, rantime): +    r_query = [] +    while len(r_query) < rantime: +        n_q = rand_ints_nodup(ran1, ran2, 2) +        if not n_q in r_query: +            r_query.append(n_q) +    return sorted(r_query) + + +from collections import defaultdict, deque, Counter +from sys import exit +from decimal import * +import heapq +import math +from fractions import gcd +import random +import string +import copy +from itertools import permutations +from operator import mul +from functools import reduce +from bisect import bisect_left, bisect_right +import sys + +sys.setrecursionlimit(1000000000) +mod = 10**9 + 7 +############# +# Main Code # +############# +N = getN() +next = [ +ans = [] -    if len(str(n)) + 1 > len(s): +    global ans +    if len(s) >= 11: +        return +    # 上限を超えない範囲で実行 +    else: -        lastnum = str(s)[-1] -        for i in listnum[int(lastnum)]: +        # dfs +        s_last = int(s[-1]) +        for i in next[s_last]: +# 始点は1~9 -ans = sorted(ans) -print((ans[m - 1])) +ans.sort() +print((ans[N - 1]))