import com.sun.org.apache.xpath.internal.operations.Bool

fun main(args: Array<String>) {
    val N = nextInt()
    fun c753(s: String): Int {
        if (s.length > 0 && s.toLong() > N) return 0
        val f = BooleanArray(10)
        s.forEach { f[it - '0'] = true }
        var count = if (f[7] && f[5] && f[3]) 1 else 0
        for (c in "753") count += c753(s + c)
        return count
    }
    val ans = c753("")
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map(String::toLong)
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
