def f(xs,l,r) if (r-l<1000) then ans=1 l.upto(r){|i| ans*=xs[i] } return ans else m=(l+r)/2 ans=f(xs,l,m) ans*=f(xs,m+1,r) return ans end end n=gets.to_i xs=gets.split(" ").map{|e| e.to_i} ans=f(xs,0,xs.size-1) while ans>9 do ans=ans.to_s.split("").map{|e| e.to_i}.sum end puts ans