N=int(input())
def count753(s):
  if int(s)>N:
    return 0
  if all(s.count(c)!=0 for c in '753'):
    ret=1
  else:
    ret=0
  for i in '753':
    ret+=count753(s+i)
  return ret
print(count753('0'))