javascript V8

var line = parseInt(readline())

var reg = new RegExp('\(3)|(4)|(7)')
var reg2 = new RegExp('\(2)|(5)|(6)|(9)')

function goodNum(line) {
    var count = 0
    for(var i=1; i<=line; i++) {
        var str = i+''
        if(reg.test(str)) {
            continue
        }
        if(!reg2.test(str)) {
            continue
        }
        count++
    }
    return count
}

console.log(goodNum(line))