N,M=map(int,input().split()) S=input() mod=10**9+7 edegs=[] for m in range(M): u,v=map(int,input().split()) u-=1;v-=1 edegs.append((u,v)) dp=[s=="P" for s in S] for t in "DCA": prev=dp dp=[0]*N for u,v in edegs: dp[u]+=prev[v] dp[v]+=prev[u] for x in range(N): dp[x]%=mod if t!=S[x]: dp[x]=0 ans=sum(dp)%mod print(ans)