class Mod def initialize(m) @MOD = m end def modPow(x, a) return x if a == 1 return (x * modPow(x, a-1)) % @MOD t = modPow(x, a / 2) (t * t) % @MOD end def modInv(x) modPow(x, @MOD - 2) end end P, N = gets.split(" ").map{|s| s.to_i} A = gets.split(" ").map{|s| s.to_i} S = gets.strip ans = A[0] mod = Mod.new(P) 0.upto(N-2) {|i| x = A[i+1] case S[i] when "+" then ans = (ans + x) % P when "-" then ans = (ans - x) % P when "*" then ans = (ans * x) % P when "/" then ans = (ans * mod.modInv(x)) % P end } puts ans