N = int(input())

def shitigosan(x):
  if int(x) > N:
    return 0
  cnt = 1 if all(x.count(c) > 0 for c in '753') else 0
  for i in "753":
    cnt += shitigosan(x+i)
  return cnt
  
print(shitigosan("0"))