import itertools
import copy as cp
X = int(input())
X_l = len(str(X))
n = ['3','5','7']
comb = [n]
all_comb = []
all_ans = []
if X < 357:
  print(0)
#comb.extend(itertools.permutations(n, len(tmp)))
#print(comb.append('a'))
for i in range(X_l - 3):
  tmp_comb = cp.copy(comb)
  for co in tmp_comb:
    for key in n:
      newco = cp.copy(co)
      newco.append(key)
      comb.append(newco)
for co in comb:
  for c in itertools.permutations(co, len(co)):
    all_comb.append(c)
#print(all_comb)  
for nums in list(set(all_comb)):
  num = int(''.join(nums))
  if num < X:
    print(num)
    all_ans.append(num)
print(len(all_ans))
