pr, n = read_line.split.map{|i|i.to_i} A = read_line.split.map{|i|i.to_i} S = read_line r = A[0].to_i64 def pow_mod(a, n, m) r = 1_i64 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].to_i64, pr - 2, pr) end r %= pr } puts r