#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0; i #define VLL vector #define VVI vector> #define VVLL vector> #define VC vector #define VS vector #define VVC vector> #define fore(i,a) for(auto &i:a) typedef pair P; template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 2147483647; const ll INFL = 9223372036854775807; const ll mod = 1000000007; VI a[100005]; string s; ll ans = 0; void dfs(int b, int c) { for (int i : a[b]) { if (c == 1 && s[i] == 'D')dfs(i, 2); else if (c == 2 && s[i] == 'C')dfs(i, 3); else if (c == 3 && s[i] == 'A')ans++; } } int main() { int n, m; cin >> n >> m >> s; REP(i, m) { int u, v; cin >> u >> v; u--, v--; a[u].push_back(v); a[v].push_back(u); } REP(i, n) { if (s[i] == 'P') dfs(i, 1); } cout << ans << endl; return 0; }