fun main(args: Array<String>) {
    abc114c()
}

fun abc114c() {
    val n = readLine()!!.toLong()

    val answer = dfs(0L, n)

    println(answer)
}

fun dfs(s: Long, n: Long): Long {
    if (s > n) return 0L

    val is753num = s.toString()
        .let { it.contains("7") && it.contains("5") && it.contains("3") }

    return dfs(s * 10 + 7, n) + dfs(s * 10 + 5, n) + dfs(s * 10 + 3, n) + if (is753num) 1 else 0
}
