'use strict'

const up = i => {
    let str = i.toString().split('')
    const last = str[str.length - 1]
    const first = str[0]

    if(str.every(v => v === '7')){
        str = str.map(v => '3')
        str.push('3')
        return parseInt(str.join(''))
    }

    if(last === '3' || last === '5'){
        return i += 2
    }
    return i += 6
}

const main = (input) => {
    const N = input.split('\n')[0]
    let count = 0
    for(let i = 357; i <= N; i = up(i)){
        let t = i.toString().split('').map(v => parseInt(v))
        if(t.every(v => v === 7 || v === 5 || v === 3)){
            let uni = [...new Set(t)]
            if(uni.length === 3){
                count++
            }
        }
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))