import cmath import sys from collections import deque, defaultdict from heapq import heappop,heappush from copy import deepcopy INF=10**18 MOD=10**9+7 MAX=10**5+7 g=[[] for i in range(MAX)] mem=[-1]*MAX def rec(u): global s, g, mem if s[u]==3: return 1 if mem[u]!=-1: return mem[u] res=0 for v in g[u]: if s[u]+1==s[v]: res+=rec(v) res%=MOD mem[u]=res return res def main(): global s, g N,M=map(int, input().split()) d={'P':0, 'D':1, 'C':2, 'A':3} s=input() s=list(map(lambda c: d[c], s)) for i in range(M): u,v=map(int, input().split()) u-=1 v-=1 if s[u]+1==s[v]: g[u].append(v) if s[v]+1==s[u]: g[v].append(u) ans=0 for i in range(N): if s[i]==0: ans+=rec(i) ans%=MOD print(ans) if __name__=='__main__': main()