function main(arg) {
    var cnt = 0;
    var other = false;
    arg = parseInt(arg);
    
    for (var i=100; i<=arg; i++ ) {
        var tmp = String(i);
        var firstDigit = String(tmp).split("")[0];
        firstDigit = parseInt(firstDigit);
 
        if(firstDigit !== 3 && firstDigit !==5 && firstDigit !== 7) {
            i = i + Math.pow(10, tmp.length - 1);
            continue;
        }
        
        if(tmp.indexOf(3) !== -1 && tmp.indexOf(5) !== -1 && tmp.indexOf(7) !== -1 && tmp.length == tmp.split(/[357]/).length-1) {
            cnt++;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
