let n = read_int ()
let f m = let cs = Array.make 8 0 in let rec f n =
  if n = 0 then cs.(3) + cs.(5) + cs.(7) = 3 else (cs.(n mod 10) <- 1; f (n / 10)) in m <= n && f m
let rec g m = let h m k = g (10 * m + k) + if f @@ 10 * m + k then 1 else 0 in if m > n then 0 else h m 3 + h m 5 + h m 7
let _ = g 0 |> Printf.printf "%d\n"