

comfortable x y = (abs $ x - y) <= 1

lunlun :: Integer -> [Integer]
lunlun 1 = [1,2,3,4,5,6,7,8,9]
lunlun n = let prev = lunlun (n-1)
            in concat (map (\x -> let one = x `mod` 10 in filter (\n -> (x*10+one)`div`10 == n`div` 10) [x*10+one-1,x * 10 +one,x*10+one+1]) prev)

lunlun_k :: Integer -> Integer -> Integer
lunlun_k n m = if toInteger(length $ lunlun m) >= n
                  then if n<0 then error $ show n ++ " " ++ show m else (lunlun m)!!fromInteger(n-1)
                  else lunlun_k (n-toInteger (length $ lunlun m)) (m+1)

main = do
  k <- read <$> getLine
  print $ lunlun_k k 1