import Control.Arrow
import Data.Sequence as Sq

q ac n
    | n < Sq.length ac = ac`index`n
    | otherwise =
    q (let (x,xs) = ((`index`0) &&& Sq.drop 1) ac in
    (if x`rem`10/=9 then(|> 10*x + x`rem`10 +1)else id)$
    (|> 10*x + x`rem`10)$
    (if x`rem`10/=0 then(|> 10*x + x`rem`10 -1)else id)
    xs) (n-1)

main = readLn>>=print.q(fromList[1..9]).pred