import itertools 
n=int(input())
ans=0
for ket in range(3,100):
  for xxx in  itertools.product([3,5,7],repeat=ket):
    tmp=list(xxx)[::1]
    hoge=0
    for j in range(len(tmp)):
      hoge=hoge*10+tmp[j]
    if(str(hoge).count("3")==0 or str(hoge).count("5")==0 or str(hoge).count("7")==0):
      ans-=1
    ans+=1
    if(hoge>=n):
      print(ans)
      exit()