function Main(input) {
    input = parseInt(input);
    answer = 0;
    for(i = 357; i <= input; i = i + 2){
        if(sevenFT(i)) answer++;
    }
    console.log(answer);
}
function sevenFT(num){
    num_S = String(num).split("");
    _three = false;
    _five = false;
    _seven = false;
    for(j = 0; j < num_S.length; j++){
        if(num_S[j] === "3"){
            num_S.splice(j, 1);
            _three = true;
        }
    }
    if(!_three) return false;
    for(j = 0; j < num_S.length; j++){
        if(num_S[j] === "5"){
            num_S.splice(j, 1);
            _five = true;
        }
    }
    if(!_five) return false;
    for(j = 0; j < num_S.length; j++){
        if(num_S[j] === "7"){
            num_S.splice(j, 1);
            _seven = true;
        }
    }
    if(!_seven) return false;
    if(num_S.length == 0){
        return true;
    }
    return false;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));