gen_ls::[String]
gen_ls = ["3","5","7"]++[ls++dig|ls<-gen_ls,dig<-["3","5","7"]]

cond::String->Bool
cond st = (elem '3' st) && (elem '5' st) && (elem '7' st)

solver::Int->Int
solver n = (length.(takeWhile (\s -> n >= read s)).(filter cond)) gen_ls

main::IO()
main=(print.solver.read)=<<getLine