fun main() {
    val n = readLine()?.toLong() ?: return
    val musts = listOf('7', '5', '3')
    val digits = n.toString().length
    val patterns = mutableListOf<Long>()

    fun gen(r: Int, c: String, m: Int) {
        if (r == 0) {
            return
        }
        musts.forEach {
            val next = c + it
            if (next.length >= m && next.toList().containsAll(musts)) {
                patterns.add(next.toLong())
            }
            gen(r - 1, next, m)
        }
    }
    gen(digits, "", 3)
    println(patterns.count { it <= n }.toString())
}
