main = getLine >>= print.solve

solve n = length ( filter (\s -> s <= n && all (`elem` s) "357" ) semi )
  where
  semi = go ["3","5","7"]
  go [] = []
  go (s:ss)
    | length s == 9 = s : go ss
    | otherwise = (:) s $ go $ ('3':s):('5':s):('7':s):ss