N = gets.chomp.to_i p = gets.chomp.split(" ").map(&:to_i) s = p.inject(:*) f = 1 def moji(s) zzz = s.to_s sl = s.to_s.length return zzz, sl end zzz, sl = moji(s) while(f) if sl > 1 yyy = 0 for i in 0...sl yyy +=zzz[i].to_i end zzz, sl= moji(yyy) else yyy = zzz[0] f = nil end end p yyy.to_i