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