n = int(input())
ans = 0
def dfs(m):
  global ans
  if m > n:
    return
  sm = str(m)
  if "3" in sm and "5" in sm and "7" in sm:
    ans += 1
  dfs(m*10+3)
  dfs(m*10+5)
  dfs(m*10+7)
dfs(0)
print(ans)