import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
 
main = abc161d

abc161d = do
    [k] <- getIntList
    let lunlunNumInfo = getLunlunNumInfo k
        lunlunL = genLunlunNum (fst lunlunNumInfo)
        groupInfo = snd lunlunNumInfo
        fstIndex = uncurry (-) groupInfo + 1
    print $ lunlunL !! (fromIntegral k - fstIndex)

-- ある群の要素数
getLunlunQty :: (Int, Int) -> Int
getLunlunQty (1, _) = 1
getLunlunQty (digit, num)
    | num == 0 = getLunlunQty (digit-1, 0) + lunlunTable !! (9 * (digit-2))
    | num == 1 = getLunlunQty (digit-1, 0) + lunlunTable !! (9 * (digit-2)) + lunlunTable !! (9 * (digit-2) + 1)
    | num == 9 = lunlunTable !! (9 * (digit-2) + 7) + lunlunTable !! (9 * (digit-2) + 8)
    | otherwise = lunlunTable !! (9 * (digit-2) + num - 2) + lunlunTable !! (9 * (digit-2) + num - 1) + lunlunTable !! (9 * (digit-2) + num)

-- getLunlunQty向けメモ
lunlunTable :: [Int]
lunlunTable = [getLunlunQty(digit, num) | digit <- [1..10], num <- [1..9]]

--((桁,上1桁), (属する群数列が、全体で何番目までの要素を持つか, 属する群数列の要素数))
getLunlunNumInfo :: Integer -> ((Int,Int), (Int, Int))
getLunlunNumInfo k = let subSums = filter (>= fromIntegral k) $ tail . reverse $ foldl' (\acc x -> (head acc + x) : acc) [0] lunlunTable
                         group = divMod (100 - length subSums) 9
                      in (group, (head subSums, getLunlunQty group))

genLunlunNum :: (Int, Int) -> [Int]
genLunlunNum (1, num) = [num]
genLunlunNum (digit, num)
    | num == 0 = genLunlunNum (digit - 1, 0) ++ genLunlunNum (digit - 1, 1)
    | num == 9 =
        map (+ 9 * (10 ^ (digit - 1))) (genLunlunNum (digit - 1, 8)) ++
        map (+ 9 * (10 ^ (digit - 1))) (genLunlunNum (digit - 1, 9))
    | otherwise =
        map (+ num * (10 ^ (digit - 1))) (genLunlunNum (digit - 1, num - 1)) ++
        map (+ num * (10 ^ (digit - 1))) (genLunlunNum (digit - 1, num)) ++
        map (+ num * (10 ^ (digit - 1))) (genLunlunNum (digit - 1, num + 1))

-- genLunlunNum向けメモ
lunlunNumList :: [[Int]]
lunlunNumList = [map (+ num * (10 ^ (digit - 1))) (genLunlunNum (digit - 1, num - 1)) | digit <-[1..3], num <- [1..9]]


readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
