use std::io;
use std::str::FromStr;
use std::collections::HashSet;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn digit(n: u64) -> u64 {
    if n == 0 {
        return 1;
    }
    for i in 0..20u32 {
        if n < 10u64.pow(i) {
            return i as u64;
        }
    }
    20u64
}

fn main() {
    let n: u64 = input();
    let digit = digit(n);
    let k = 3u64;
    let mut count = 0;
    for d in 3..(digit+1) {
        for mask in 0..k.pow(d as u32) {
            let mut tmp = mask;
            let mut num: u64 = 0;
            for i in 0..d {
                let val = tmp % k;
                match val {
                    0 => num = num * 10 + 7,
                    1 => num = num * 10 + 5,
                    2 => num = num * 10 + 3,
                    _ => print!("0")
                }
                tmp /= k;
            }
            if num < n {
                let c: Vec<char> = num.to_string().chars().collect();
                if c.contains(&'7') && c.contains(&'5') && c.contains(&'3') {
                    // println!("{}", num);
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}
