'use strict';
const main = input => {
    const n = parseInt(input[0], 10);
    let ans = 0;
    const sft = (val, num, n) => {
        
        // console.log(num);
        
        let Num = 10*num + val;
        let NumString = Num.toString();
        if(n>=Num) {
            if(NumString.indexOf('3')!= -1 && NumString.indexOf('5')!= -1 && NumString.indexOf('7')!= -1) ans++;
            sft(7, Num, n);
            sft(5, Num, n);
            sft(3, Num, n);
        }

    };
    sft(0, 0, n);
    console.log(ans);
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));