import Data.List

makeLunlunNumberList :: [Integer] -> [Integer]
makeLunlunNumberList xs = foldl f [] xs
                                       where f = (\xs x -> do
                                                 let xd0 = x `mod` 10 
                                                 let a = x*10 + xd0
                                                 if xd0 == 0 then a : a+1 : xs else if xd0 == 9 then a-1 : a : xs else a-1 : a : a+1 : xs)

solve :: Int -> [Integer] -> Integer
solve k lnl = if length lnl >= k
                 then (sort lnl) !! (k-1)
                 else solve (k-(length lnl)) (makeLunlunNumberList lnl)

main = do
    k <- readLn :: IO Int
    print $ solve k [1..9]
