import itertools as t;N,a,X=input(),0,[]
for i in range(len(N)+1):X+=list(t.product((3,5,7),repeat=i))
for i in X:
    s=''
    for j in i:s+=str(j)
    if len(set(i))>2and int(s)<=int(N):a+=1
print(a)