import copy

def saiki(s,used,n):
  if int(s) > n:
    return 0

  count = 0
  arr = ['7','5','3']
  if len(used) == 3:
    count += 1
  
  for c in arr:
    cp_used = copy.deepcopy(used)
    cp_used.add(c)
    count += saiki(s+c,cp_used,n)
    
  return count
  

n = int(input())

ans = 0
array = []

used = set()
ans = saiki('7',set('7'),n) + saiki('5',set('5'),n) + saiki('3',set('3'),n)
print(ans)