const CHARS_753: [char; 3] = ['7', '5', '3'];

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

fn count(s: &String, c: char) -> i32 {
    let chars_vec: Vec<char> = s.chars().collect();
    chars_vec.iter().filter(|cmp_c| **cmp_c == c).count() as i32
}

fn dfs(s: String, n: i32) -> i32 {
    if s.parse::<i32>().unwrap_or(0) > n {
        0
    }
    else {
        let is_753   = CHARS_753.iter().all(|c| count(&s, *c) > 0);
        let sum: i32 = CHARS_753.iter().map(|c| {
            let mut new_string = s.clone();
            new_string.push(*c);
            dfs(new_string, n)
        }).sum();
        sum + if is_753 { 1 } else { 0 }
    }
}

fn main() {
    let n: i32 = read();
    println!("{}", dfs("".to_string(), n));
}
