solve :: Int -> Int solve n = length $ filter (<=n) $ map (*(10^9 + 1)) $ concat $ map (\x -> map (*x) [1..9]) [1,11,111,1111] main = readLn >>= print . solve