require "big" pr, n = read_line.split.map{|i|i.to_i64} a = read_line.split.map{|i|i.to_i64} s = read_line r = a[0].to_i64 def pow_mod(a, n, m) r = BigInt.new(1) a = BigInt.new(a) while n > 0 if n % 2 == 1 r *= a r %= m end a **= 2 a %= m n >>= 1 end r end (n - 1).times{|i| case s[i] when '+' r += a[i + 1] when '-' r -= a[i + 1] when '*' r *= a[i + 1] when '/' r *= pow_mod(a[i + 1], pr - 2, pr) end r %= pr } puts r