n = gets.to_i
d = n.to_s.size

sft = ["3", "5", "7"]
res = 0

1.step(d) do |t|
  sft.repeated_permutation(t).each do |p|
    if sft & p == sft
      x = p.join("").to_i
      if x > n
        break
      end
      res += 1
    end
  end 
end
puts res