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
    ls = iterate nextLunlun [] :: [[Int]]
    l = map unsafeDigitToChar . reverse . head . drop k $ ls :: String
  putStrLn l

nextLunlun :: [Int] -> [Int]
nextLunlun [] = [1]
nextLunlun (d : []) | d < 9     = [succ d]
nextLunlun (d : ds@(d' : _)) | d < d' || d == d' && d' < 9 = succ d : ds
nextLunlun (_ : ds) | d' == 0   = 0 : ds'
                    | otherwise = pred d' : ds'
  where
    ds'@(d' : _) = nextLunlun ds

unsafeDigitToChar :: Int -> Char
unsafeDigitToChar = toEnum . (+ 48)

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