import Control.Monad

solve :: Int -> [String]
solve 3 = replicateM 3 "753"
solve n = replicateM n "753" ++ solve (n - 1)

main :: IO ()
main = do
  s <- getLine
  let check = filter (\x -> '7' `elem` x && '5' `elem` x && '3' `elem` x)
  let list = map read $ check $ solve $ length s :: [Int]
  print . length $ filter (<= read s) list