local mod = false local mfl = math.floor local function bmul(x, y) if x < y then x, y = y, x end local res = 0 while 0 < y do if y % 2 == 1 then res = (res + x) % mod y = y - 1 end x = (x + x) % mod y = mfl(y / 2) end return res end local function badd(x, y) return (x + y) % mod end local function bsub(x, y) return x < y and x - y + mod or x - y end local function modpow(src, pow) local res = 1 while 0 < pow do if pow % 2 == 1 then res = bmul(res, src) pow = pow - 1 end src = bmul(src, src) pow = mfl(pow / 2) end return res end local function modinv(src) return modpow(src, mod - 2) end local p, n = io.read("*n", "*n") mod = p local a = {} for i = 1, n do a[i] = io.read("*n") end io.read() local s = io.read() local ans = a[1] for i = 1, n - 1 do local ss = s:sub(i, i) if ss == "+" then ans = badd(ans, a[i + 1]) elseif ss == "-" then ans = bsub(ans, a[i + 1]) elseif ss == "*" then ans = bmul(ans, a[i + 1]) else ans = bmul(ans, modinv(a[i + 1])) end end print(ans)