import           Data.Sequence (Seq ((:<|)), index, (|>))
import qualified Data.Sequence as S


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

solve :: Int -> Int
solve k = index (xs !! (k - 1)) 0
  where xs = iterate f $ S.fromList [1 .. 9]

f :: Seq Int -> Seq Int
f (x :<| xs) = xs'''
  where y = x `mod` 10
        z = 10 * x + y
        xs' = if y /= 0 then xs |> z - 1 else xs
        xs'' = xs' |> z
        xs''' = if y /= 9 then xs'' |> z + 1 else xs''
