open System

let K = int <| Console.ReadLine()

let rec g = function 
    | [] -> []
    | [x] -> [x]
    | x::xs -> x :: (g xs)

let rec f: int * int list -> int list = function
    | 0, xs -> xs 
    | n, x::xs -> f (n - 1, xs)
    | n, xs -> f (n - 1, xs)

let runrun = 
    let rec f (n: int) (xs: int list) =
        seq {
            match n, xs with
            | 0, xss -> xss 
            | n, [] -> for i in 1..9 do yield! f (n - 1) [i]
            | n, x::xs->
                if x > 0 then  yield! f (n - 1) ((x - 1)::x::xs)
                yield! f (n - 1) (x::x::xs)
                if x < 9 then yield! f (n - 1) ((x + 1)::x::xs)
        }
    let ls2num = List.rev >> List.fold (fun acc x -> acc * 10L + int64 x) 0L
    seq {
        for digits in Seq.initInfinite((+) 1) do 
            yield! f digits [] |> Seq.map ls2num
    }

runrun
|> Seq.item (K-1)
|> printfn "%i"