fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val length = n.toString().length

    if (n < 357) {
        println(0)
        return
    }

    val list = listOf("3", "5", "7")
    val result = mutableListOf<String>()
    fun dfs(s: String) {
        if (3 <= s.length) {
            result.add(s)

            if (s.length == length) {
                return
            }
        }
        list.forEach {
            dfs(it + s)
        }
    }

    dfs("")
    result.filter { it.contains("5") && it.contains("3") && it.contains("7") }
        .map(String::toInt)
        .filter { n >= it }
        .size.let(::println)

}

