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

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

    var count = 0L
    var set = hashSetOf<Long>()
    list753.forEach { a ->

        list753.forEach { b ->

            list753.forEach { c ->

                list753.forEach { d ->

                    list753.forEach { e ->

                        list753.forEach { f ->

                            list753.forEach { g ->

                                list753.forEach { h ->
                                    list753.forEach { i ->
                                        list753.forEach { j ->
                                            val s = a + b + c + d + e + f + g + h + i + j
                                            (3..9).forEach {
                                                val sub = s.take(it)
                                                val numericSub = sub.toLong()
                                                if (!set.contains(numericSub) && numericSub <= N && sub.contains("7") && sub.contains("5") && sub.contains("3")) {
                                                    count++
                                                    set.add(numericSub)
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    println(count)
}