import sys input=lambda: sys.stdin.readline().rstrip() p,n=map(int,input().split()) A=[int(i) for i in input().split()] S=input() ans=A[0] for i in range(n-1): if S[i]=="+": ans=ans+A[i+1] if S[i]=="-": ans=ans-A[i+1] if S[i]=="*": ans=ans*A[i+1] if S[i]=="/": ans=(ans*pow(A[i+1],p-2,p))%p print(ans)