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