open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
let outl s = stdout.WriteLine(s|>string)
let outsep ls = stdout.WriteLine(String.concat " " (ls|>Array.map string))
let outsepl ls = stdout.WriteLine(String.concat "\n" (ls|>Array.map string))
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let K=R int
    let ans = (Array.append ([|1;2;3;4;5;6;7;8;9|]) (Array.zeroCreate K))|>Array.map int64
    let mutable i,j=(0,9)
    while j<=K do
        let nx = ans.[i]
        let r = nx%10L
        if r>0L then
            ans.[j] <- nx*10L+(r-1L)
            j <- j+1
        ans.[j]<- nx*10L+r
        j<-j+1
        if r<9L then
            ans.[j] <- nx*10L+(r+1L)
            j<-j+1
        i<-i+1
    ans
    |>Array.filter(fun c->c<>0L)
    |>Array.sort
    |>fun c->c.[K-1]
    |>outl
    0
