from itertools import product
n = int(input())
ans = 0
S = []
for i in range(10):
    S += list(product("357",repeat=i))
for s in S:
  if len(set(s)) > 2 and int("".join(s)) <= n:
    ans += 1
print(ans)    