from itertools import product
n=int(input())
ans=0
for i in range(3,10):
    l=list(product(["3","5","7"],repeat=i))
    for j in l:
        ans+=(int("".join(list(j)))<=n and len(set(j))==3)
print(ans)