

fun main(args:Array<String>) {
    maxNum = readLine()!!.toLong()
    val ans = getAns(0,0)
    println(ans)
}


var maxNum:Long = 0
var set = mutableSetOf<Long>()

fun getAns(flag:Int, subtotal:Long):Long {
    if(subtotal > maxNum) {
        return 0
    }


    var ans:Long = 0
    if(flag == 7) {
        ans = 1
    }
    for(i in listOf(3,5,7)) {
        var newFlag = flag
        if(i == 3) {
            newFlag = (flag or 1)
        }
        if(i == 5) {
            newFlag = (flag or 2)
        }
        if (i == 7) {
            newFlag = (flag or 4)
        }
        val ret = getAns(newFlag, subtotal * 10 + i)
        ans += ret
    }
    return ans
}