fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    println(Solver(n).solve())
}

private class Solver(private val n: Int) {

    fun solve(): Int {
        return f("0")
    }

    private fun f(s: String): Int {
        if (s.toLong() > n) {
            return 0
        }

        var r = 0

        if (s.contains('3') && s.contains('5') && s.contains('7')) {
            r++
        }

        r += f(s + '3')
        r += f(s + '5')
        r += f(s + '7')

        return r
    }

}
