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 = if m > n then 0 else List.fold_left (fun c k -> c + g (10 * m + k) + if f @@ 10 * m + k then 1 else 0) 0 [3; 5; 7]
let _ = g 0 |> Printf.printf "%d\n"