M,n=map(int,input().split()) a=list(map(int,input().split())) x=a[0] for c,y in zip(list(input()),a[1:]): if c=="+": x=(x+y)%M if c=="-": x=(x-y)%M if c=="*": x=(x*y)%M if c=="/": x=(x*pow(y,M-2,M))%M print(x)