let n = read_int () in
let judge i =
    let rec loop i flag =
        if i = 0 then (flag = 7) else
            let flag = match i mod 10 with
            | 3 -> flag lor 1
            | 5 -> flag lor 2
            | 7 -> flag lor 4
            | _ -> flag
            in
            loop (i / 10) flag
    in
    loop i 0
in
let rec loop i acc =
    if i > n then acc else
        let acc = if judge i then acc + 1 else acc in
        let acc = loop (i * 10 + 3) acc in
        let acc = loop (i * 10 + 5) acc in
        let acc = loop (i * 10 + 7) acc in
        acc
in
loop 0 0 |> Printf.printf "%d\n"