fun main(args: Array<String>) = yorukatsu13d()

fun yorukatsu13d() {
    val n = readLine()!!.toLong()

    val list = setOf('3', '5', '7')

    var answer = 0

    fun dfs(num: Long) {
        if (num > n) return
        if (num.toString().toSet() == list) answer++
        for (c in list) dfs(num * 10 + Character.getNumericValue(c))
    }

    dfs(0L)

    println(answer)
}
