N = int(input())
count = 0
for i in range(1, N+1):
  x = str(i)
  if '1' not in x and '2' not in x and '4' not in x and '6' not in x and '8' not in x and '9' not in x and '0' not in x and '3' in x and '5' in x and '7' in x:
    count += 1
print(count)