var ans = 0

fun main(args: Array<String>) {
    val n = readInputLine().toLong()

    dfs(n, 0L)

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun dfs(n: Long, s: Long) {
    if (s > n) {
        return
    }
    
    val sString = s.toString()
    if (sString.contains('7') && sString.contains('5') && sString.contains('3')) {
        ans++
    }
    
    dfs(n, s * 10L + 7L)
    dfs(n, s * 10L + 5L)
    dfs(n, s * 10L + 3L)
}
