fun main(args:Array<String>) {
	val ns = readLine()!!
	val len = ns.length
	val n = ns.toInt()
	println((1..9).sumBy {enum753(it,IntArray(it),0,n)})
	
}


fun enum753(len: Int ,x:IntArray, count:Int,n:Int): Int{
	if(len==0) {return if(3 in x && 5 in x && 7 in x &&
			x.joinToString("").toInt()<=n) count+1 else count}
	x[len-1]=3
	val c3 = enum753(len-1,x,count,n)
	x[len-1]=5
	val c5 = enum753(len-1,x,count,n)
	x[len-1]=7
	val c7 = enum753(len-1,x,count,n)
	return c3+c5+c7
}