#abc114c
import itertools

a=raw_input()
n=int(a)
res=0
for i in xrange(1,len(a)+1):
 for s in itertools.product('753',repeat=i):
  m=int("".join(s))
  if len(set(s))==3 and m<=n:
   res+=1
print res
