#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};


// abcde
fn read_string() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}


fn read_as_primitive<T: FromStr>() -> T {
    let s = read_string();
    s.parse().ok().expect("failed to parse input")
}


fn integerdigits(n: i64) -> Vec<i64> {
    let s = n.to_string();
    assert!(s.chars().next().unwrap() != '-');
    s.chars().map(|c| c.to_digit(10).unwrap() as i64).collect()
}

fn dfs(x: i64, n: i64) -> i64 {
    if x > n {
        return 0;
    }
    let digits = integerdigits(x);
    let mut ret = if digits.contains(&3) && digits.contains(&5) && digits.contains(&7) {1} else {0};
    for c in &[7, 5, 3] {
        ret += dfs(10 * x + c, n);
    }
    ret
}
    
fn main() {
    let n: i64 = read_as_primitive();
    println!("{}", dfs(0, n));
}