n = input()
from itertools import product
from collectins import Counter
sum = 0
for i in range(len(n)-2):
  for j in product("753", repeat=i+3):
    if int(''.join(j)) <= int(n) and len(Counter(j))==3:
      sum+=1
print(sum)