P,N = map(int, input().split()) A = [int(a) for a in input().split()] S = 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)