p, n= map(int, input().split()) A = list(map(int, input().split())) s = str(input()) ans = A[0] for i in range(n-1): if s[i] == '+': ans += A[i+1] elif s[i] == '-': ans -= A[i+1] elif s[i] == '*': ans *= A[i+1] else: ans *= pow(A[i+1], p-2, p) ans %= p print(ans)