class Integer def mod_inverse(mod) self.pow(mod - 2, mod) end end P, N = gets.split.map(&:to_i) A = gets.split.map(&:to_i) S = gets.chomp.chars val = A[0] (N - 1).times do |i| a = A[i + 1] s = S[i] if s == '/' val = eval("val * a.mod_inverse(P)") else val = eval("val #{s} a") end val %= P end puts val