n = gets.to_i
digits = n.to_s.length
ans = 0
(3..digits).each do |d|
  c = [3,5,7].repeated_permutation(d).count do |i|
    i.join.to_i <= n && i.include?(3) && i.include?(5) && i.include?(7)
  end
  ans += c
end

puts ans
