#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, m;
int head[MAXN], ncnt;
char ch[2][4] = {{'A', 'A', 'B', 'B'}, {'B', 'B', 'A', 'A'}};
char s[MAXN];
struct node {
  int v, nex;
} edge[MAXN * 2];
void addedge(int u, int v) {
  node &p = edge[++ncnt];
  p.v = v;
  p.nex = head[u];
  head[u] = ncnt;
}
void dfs(int u, int st, char *ch, int lim, int dep = 1) {
  if (dep == 4 * lim + 1) {
    if (u == st) {
      puts("Yes");
      exit(0);
    }
    return;
  }
  for (int i = head[u]; i; i = edge[i].nex) {
    int v = edge[i].v;
    if (dep != 4 * lim && s[v] != ch[dep % 4]) continue;
    dfs(v, st, ch, lim, dep + 1);
  }
}
int main() {
  scanf("%d%d%s", &n, &m, s + 1);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  for (int lim = 1; lim <= 100; lim++)
    for (int i = 1; i <= n; i++) dfs(i, i, s[i] == 'A' ? ch[0] : ch[1], lim);
  puts("No");
}
