n=int(input())
c=0
for i in range(n):
    s=str(i)
    if s.count("7")>0 and s.count("5")>0 and s.count("3")>0 and s.count("1")==0 and s.count("2")==0 and s.count("4")==0 and s.count("6")==0 and s.count("8")==0 and s.count("9")==0 and s.count("0")==0:
        c+=1
print(c)
