a = gets.chomp.to_i
sichi = ["7","5","3"]
anan = []
for ap in 0..9
	anan.push(sichi.repeated_permutation(ap).collect {|aa| aa.join}.delete_if{|aa| aa.count("7") == 0 || aa.count("5") == 0 || aa.count("3") == 0})
end
puts anan.flatten.map(&:to_i).delete_if{|aa| aa > a }.size