import itertools
n = input()
keta = len(list(n))
cnt=0
l = [3,5,7]
for k in range(3,keta+1):
  for i in itertools.product(l, repeat=k):
    if 3 in i and 5 in i and 7 in i:
      tmp=""
      for j in i:
        tmp+=str(j)
      if int(tmp)<int(n):
        cnt+=1
      else:
        break
print(cnt)