#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        N: i64,
    }

    let mut q: Vec<i64> = Vec::new();
    q.push(357);
    q.push(375);
    q.push(537);
    q.push(573);
    q.push(735);
    q.push(753);

    for digit in 4..=9 {
        // 3^digit通り
        let mut stack: Vec<Vec<char>> = Vec::new();
        stack.push(vec!['3']);
        stack.push(vec!['5']);
        stack.push(vec!['7']);
        while !stack.is_empty() {
            let state = stack.pop().unwrap();

            if state.len() == digit {
                let mut contains_three = false;
                let mut contains_five = false;
                let mut contains_seven = false;

                for i in 0..digit {
                    if state[i] == '3' {
                        contains_three = true;
                    }
                    if state[i] == '5' {
                        contains_five = true;
                    }
                    if state[i] == '7' {
                        contains_seven = true;
                    }
                }

                if contains_three && contains_five && contains_seven {
                    // OK
                    let num_s: String = state.iter().collect();
                    let num: i64 = num_s.parse().unwrap();
                    q.push(num);
                }
            } else {
                let mut s3 = state.clone();
                s3.push('3');
                stack.push(s3);

                let mut s5 = state.clone();
                s5.push('5');
                stack.push(s5);

                let mut s7 = state.clone();
                s7.push('7');
                stack.push(s7);
            }
        }
    }

    q.sort();

    let mut ans = 0;
    for &i in q.iter() {
        if i < N {
            ans += 1;
        }
    }
    println!("{}", ans);
}
