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] def pow_mod(a, n, m) r = 1 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