check :: String -> Bool
check x = '7' `elem` x && '5' `elem` x && '3' `elem` x

solve :: Int -> String -> Int
solve n s
  | s /= "" && read s > n = 0
  | otherwise = solve n (s ++ "7")
              + solve n (s ++ "5")
              + solve n (s ++ "3")
              + if check s then 1 else 0

main :: IO ()
main = do
  n <- readLn
  print $ solve n ""