from itertools import product
N, = map(int, raw_input().split())
M = len(str(N))
r = 0
for i in range(1, M+1):
  for s in product("357", repeat=i):
    x = int("".join(s))
    if "3" in s and "5" in s and "7" in s and x <= N:
      r += 1
print r