fun main(args: Array<String>) {
    val sub = mutableListOf(0)
    val list = mutableListOf<Int>()
    repeat(9) {
        val l = sub.toList()
        sub.clear()
        for (ln in l) {
            for (n in ln * 10 + 3..ln * 10 + 7 step 2) {
                sub.add(n)
                if ("357".all { n.toString().contains(it) }) list.add(n)
            }
        }
    }
    print(readLine()!!.toLong().let { n -> list.count { it <= n } })
}