n = int(input())

def dfs(s): #文字列sで始まる個数
  if int(s) > n:
    return 0
  ret = 1 if all(s.count(c) > 0 for c in "753") else 0
  for c in '753':
    ret += dfs(s + c)
  return ret

print(dfs('0'))
  

