N = gets.to_i

def solve(value, used,counter)
  return if value > N
  counter[0] += 1 if used == 0b111

  solve(value*10 + 7, used | 0b001,counter)
  solve(value*10 + 5, used | 0b010,counter)
  solve(value*10 + 3, used | 0b100,counter)
end

counter = [0]
solve(0,0,counter)
puts counter[0]
