x = 1 n = gets.to_i a = gets.chomp.split(" ") for i in 0..n-1 x *= a[i].to_i end while x>=10 y = 0 while x>0 y+=x%10 x/=10 end x=y end print x