from itertools import product

N = input()
ans = 0
for i in range(3,10):
  for b in product("753", repeat=i):
    if int("".join(b))<=N and "7" in b and "5" in b and "3" in b:
      ans += 1
print ans
