w="0357"
v=[p [a,b,c,d,e,f,g,h,i,j]|a<-w,b<-w,c<-w,d<-w,e<-w,f<-w,g<-w,h<-w,i<-w,j<-w]
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)]]))