import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,M = map(int,readline().split()) words = '$' + readline().decode().rstrip() m = map(int,read().split()) UV = tuple(zip(m,m)) MOD = 10**9 + 7 UV += tuple((v,u) for u,v in UV) dp = [1 * (s == 'P') for s in words] for T in 'DCA': newdp = [0] * (N+1) for u,v in UV: if words[v] == T: newdp[v] += dp[u] dp = newdp answer = sum(dp) % MOD print(answer)