from collections import deque
N = int(input())
stack, seen = deque(["0"]), deque([])
c = 0
while stack:
  x = stack.pop()
  seen.append(x)
  if int(x)>N:
    continue
  if all(x.count(i)>0 for i in "753"):
    c += 1
  for i in "753":
    if x+i in seen:
      continue
    else:
      stack.append(x+i)
print(c)