N = gets.chomp.to_i p = gets.chomp.split(" ").map(&:to_i) #s = p.inject(:*) if p.include?(0) s = 0 else s = 1 p.each do |i| s*=i end end if s==0 p 0 elsif s%9 ==0 p 9 else p s%9 end