import Control.Monad
v=(map p) (replicateM 10 "0357")
u=[x|x<-v,not(elem '0' x),elem '3' x,elem '5' x,elem '7' x]
p ('0':s) = p s
p [] = "0"
p s = s
main=readLn>>=print.(\n->(sum[1|x<-[x|x<-u,(read x)<=(n::Int)]]))