fun main(args : Array<String>) {
    val N = readLine()!!.toLong()

    val list753 = listOf("7", "5", "3")
    val maxDigits = Math.log10(N.toDouble()).toInt() + 1

    fun is753(string: String) : Boolean {
        return string.contains("7") && string.contains("3") && string.contains("5")
    }

    fun dfs(s: String) : Int {
        var count = 0
        if (is753(s) && s.toLong() <= N) {
            count++
        }
        if (s.length == maxDigits) {
            return count
        }

        list753.forEach {
            count += dfs(s + it)
        }
        return count
    }

    println(dfs(""))
}