import itertools

N = input()

A = []
nums = [3,5,7]
con = 0

for i in range(3,len(N) + 1):
  A += list(itertools.product(nums,repeat = i))

L = []

for i in range(0,len(A)):
  a = set(list(A[i]))
  if len(a) == 3:
    L.append(A[i])

Slist = []
    
for i in range(0,len(L)):
  S = ""
  for j in range(0,len(L[i])):
    S += str(L[i][j])
  S = int(S)
  Slist.append(S)

print(len([c for c in Slist if c < int(N)]))