import qualified Data.Vector.Unboxed as U

main = do
  k <- readLn :: IO Int
  print $ solve k

solve k = f k $ U.fromList [1..9] where
  f 1 ll = U.head ll
  f k ll
    | k <= U.length ll = ll U.! pred k
    | otherwise = f (k - U.length ll) $ U.concatMap g ll
    where
      g x = U.fromList $ case mod x 10 of
        0 -> [10*x, 10*x+1]
        9 -> [10*x+8, 10*x+9]
        r -> [10*x+r-1 .. 10*x+r+1]