main = do
    putStrLn . show . solve =<< getLine

-- |
-- >>> solve "575"
-- 4
-- >>> solve "3600"
-- 13
-- >>> solve "999999999"
-- 26484

solve s = length . filter pred . concat $ candidates
  where
    prepend = concatMap (\x -> ['3':x, '5':x, '7':x])
    candidates = take (length s) $ iterate prepend ["3", "5", "7"]
    pred s'
        | (read s' :: Int) > (read s :: Int) = False
        | '3' `elem` s' && '5' `elem` s' && '7' `elem` s' = True
        | otherwise            = False
