N = input()
counter = 0

for i in range(1, int(N)+1):
  a = list(str(i))
  if '7' in a and '5' in a and '3' in a and '1'not in a and '2' not in a and '4' not in a and '6' not in a and '8' not in a and '9' not in a:
    counter += 1
print(counter)