from sys import stdin
b = "357"
def valid(m):
 m = str(m)
 for i in b:
  if i not in m:
   return 0
 return 1
a = [3,5,7]
n = int(stdin.readline())
ans = 0
i = 0
while True:
 if i >= len(a):
  break
 cur = a[i]
 if cur > n:
  break
 if valid(cur):
  ans+=1
 a.append(cur*10 + 3); a.append(cur*10 + 5); a.append(cur*10 + 7)
 i+=1
print ans