P,N=map(int,input().split()) A=list(map(int,input().split())) S=input() ans=A[0] for a,s in zip(A[1:],S): if s=="+": ans+=a elif s=="-": ans-=a elif s=="*": ans*=a else: ans*=pow(a,P-2,P) ans%=P print(ans)