function main(input) {
    const n = parseInt(input);
    const count = function(t) {
        if (n < t) return 0;
        const ts = t.toString();
        let cnt =  0 <= ts.indexOf('7') && 0 <= ts.indexOf('5') && 0 <= ts.indexOf('3') ? 1 : 0;
        [7, 3, 5].forEach(function(i) {
            cnt += count(10 * t + i);
        });
        return cnt;
    };
    console.log(count(0));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
