import itertools

n = int(input())
m = len(str(n))
def f(n,m):
  s = [7,5,3]
  y = [int(''.join(list(i))) for i in itertools.product(s, repeat=m)]
  y = [i for i in y if i <= n and str(i) in 7 and str(i) in 5 and str(i) in 3]
  return len(y)
print(f(n,m))