N = input().strip()

base = set(['375', '357', '537', '573', '735', '753'])

if int(N) < 357:
  print(0)
else:
  for n in range(len(N) - 3):
    newb = set()
    for b in base:
      new3b = set([b[:i] + '3' + b[i:] for i in range(len(b) + 1)])
      new5b = set([b[:i] + '5' + b[i:] for i in range(len(b) + 1)])
      new7b = set([b[:i] + '7' + b[i:] for i in range(len(b) + 1)])
      newb |= new3b | new5b | new7b
    base |= newb

print(len([i for i in base if int(i) <= int(N)]))
