fun main(args : Array<String>) {
    val N = readLine()!!.toLong()
    count(0, N)
    println(cnt)
}

var cnt = 0
fun count(num: Long, limit: Long) {
    if (num > limit) {
        return
    }

    if (is753(num)) {
        cnt++
    }

    count(num * 10 + 3, limit)
    count(num * 10 + 5, limit)
    count(num * 10 + 7, limit)
}



fun is753(num: Long) : Boolean {
    val str = num.toString()
    return str.contains("7") && str.contains("5") && str.contains("3")
}
