import Data.Bool (bool)

main :: IO ()
main = readLn >>= print . solver

solver :: Int -> Int
solver n = go 0 False False False
  where
    go c s f t
      | c > n     = 0
      | otherwise = (bool 0 1 (and [s,f,t]))
      + go (10 * c + 7) True f t
      + go (10 * c + 5) s True t
      + go (10 * c + 3) s f True