import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

main = do
  n <- (read::String -> Int) <$> getLine
  print $ solve n 1


solve::Int -> Int -> Int
solve n digit
  | n < digit = 0
  | n >= digit * 10 = digit * 9 + solve n (digit * 100)
  | otherwise = n - digit + 1
