class Array
  include Comparable
end

n = gets.to_s.to_i

cnt = 0
3.upto(n.to_s.size) do |i|
  [3, 5, 7].repeated_permutation(i) do |a|
    break if a.join.to_i > n
    cnt += 1 if a.include?(3) && a.include?(5) && a.include?(7)
  end
end

puts cnt