from collections import deque
N = int(input())
Q = deque(["357"])
count = 0
for q in range(357,N):
  q = str(q)
  if "0" not in q and "1" not in q and "2" not in q and "4" not in q and "6" not in q and "8" not in q and "9" not in q and "7" in q and "5" in q and "3" in q:
    count += 1
print(count)