N = gets.to_i p = gets.split(" ").map(&:to_i) s = p.inject(:*) if s==0 p 0 elsif s%9 ==0 p 9 else p s%9 end