N=int(input())
def dfs(str):
  if int(str)>N:
    return 0
  if all(str.count(base)>0 for base in '753'):
    ans=1
  else:
    ans=0
  for base in '753':
    ans+=dfs(str+base)
  return ans
print(dfs('0'))