import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (k : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    queue = [1..9] ++ f queue :: [Int]
      where
        f (l : ls) = g l ++ f ls
        g l | d == 0    = [l', l' + 1]
            | d == 9    = [l' + 8, l' + 9]
            | otherwise = [l' + pred d, l' + d, l' + succ d]
          where
            d = l `mod` 10
            l' = 10 * l
  print . head . drop (pred k) $ queue

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
