N = gets.to_i A = gets.split.map(&:to_i) MOD = 10 ** 9 + 7 min_a, max_a = A.minmax if min_a == 0 puts -1 exit end if max_a >= 4 puts MOD end res = 1 A.each do |a| res *= a.pow((1..a).inject(:*)) if res > MOD puts MOD exit end end puts MOD % res