import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun countNum(S: String, NMAX: Int): Long {
    var s = S
    val N = s.length
    for (i in N until NMAX) {
        s = "0$s"
    }
    val dp = Array(NMAX+1){Array(2){
        Array(2){Array(2){Array(2){Array(2){
            LongArray(2) { 0 }
        }}}}
    }}
    dp[0][0][0][0][0][0][0] = 1L
    for (i in 0 until NMAX) {
        for (j in 0 until 2) {
            for (c1 in 0 until 2) {
                for (c2 in 0 until 2) {
                    for (c3 in 0 until 2) {
                        for (c4 in 0 until 2) {
                            for (c5 in 0 until 2) {
                                val lim = if (j == 1) 9 else s[i]-'0'
                                for (d in 0 .. lim) {
                                    val less = if (d<lim) 1 else 0
                                    val three = if (d == 3) 1 else 0
                                    val five = if (d == 5) 1 else 0
                                    val seven = if (d == 7) 1 else 0
                                    val notZero = if (d != 0) 1 else 0
                                    val except357 = if (c4 == 1) {
                                        if (d!=3 && d!=5 && d!=7) 1 else 0
                                    } else {
                                        if (d!=0 && d!=3 && d!=5 && d!=7) 1 else 0
                                    }
                                    dp[i+1][j or less][c1 or three][c2 or five][c3 or seven][c4 or notZero][c5 or except357] +=
                                            dp[i][j][c1][c2][c3][c4][c5]
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    var res = 0L
    for (j in 0 until 2) {
        for (c1 in 0 until 2) {
            for (c2 in 0 until 2) {
                for (c3 in 0 until 2) {
                    for (c4 in 0 until 2) {
                        for (c5 in 0 until 2) {
                            if (c1 == 1 && c2 == 1 && c3 == 1 && c4 == 1 && c5 == 0) {
                                res +=  dp[NMAX][j][c1][c2][c3][c4][c5]
                            }
                        }
                    }
                }
            }
        }
    }
    return res
}


fun solve() {
    val S = rd.readString()

    val ans = countNum(S, 10)

    println(ans)
}


//val rd = debug.Reader("abc", "114", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 34620