class Mod def initialize(m) @MOD = m end def modPow(x, n) res = 1 while n > 0 do res = res * x % @MOD if n & 1 != 0 x = x * x % @MOD n >>= 1 end res 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