n = int(input())

def dfs(num):  
  if(int(num) > n):
    return 0
  res = 1 if(all(num.count(c) > 0 for c in "753")) else 0
  for i in "753":
    res += dfs(num + i)

  return res

print(dfs("0"))  
