import Data.List
import qualified Data.Vector.Unboxed as U

main = do
  k <- readLn :: IO Int
  print $ genLunLun k U.! pred k

genLunLun :: Int -> U.Vector Int
genLunLun k = gen (U.fromList [1..9]) where
  gen lunlun
    | U.length lunlun >= k = lunlun
    | otherwise = lunlun U.++ U.concatMap f lunlun
    where
      f x
        | r == 0 = U.fromList [x*10, x*10+1]
        | r == 9 = U.fromList [x*10+8, x*10+9]
        | otherwise = U.fromList [x*10+r-1 .. x*10+r+1]
        where r = mod x 10
  