#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int MAXN = 2e5 + 5;
vector<int> gr[MAXN];
int n, m, c[MAXN];
char s[MAXN];
bool dfs(int u, int t, int d) {
  if (d != u) c[u] = t;
  bool f = 0;
  if (s[u] == 'A') {
    if (t == 1) {
      for (int i = 0; i < gr[u].size() && !f; i++) {
        int v = gr[u][i];
        if (s[v] == 'A') {
          if (c[v] == -1 || u == v) f = dfs(v, 2, u);
        }
      }
    }
    if (t == 2) {
      for (int i = 0; i < gr[u].size() && !f; i++) {
        int v = gr[u][i];
        if (s[v] == 'B' && c[v] == -1) f = dfs(v, 1, u);
      }
    }
  }
  if (s[u] == 'B') {
    if (t == 1) {
      for (int i = 0; i < gr[u].size() && !f; i++) {
        int v = gr[u][i];
        if (s[v] == 'B') {
          if (c[v] == -1 || u == v) f = dfs(v, 2, u);
        }
      }
    }
    if (t == 2) {
      for (int i = 0; i < gr[u].size() && !f; i++) {
        int v = gr[u][i];
        if (s[v] == 'A' && c[v] == 1) return true;
        if (s[v] == 'A' && c[v] == -1) f = dfs(v, 1, u);
      }
    }
  }
  if (!f && d != u) c[u] = 0;
  return f;
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%s", s);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  memset(c, -1, sizeof(c));
  bool f = 0;
  for (int i = 0; i < n && !f; i++) {
    if (c[i] == -1 && s[i] == 'A') f = dfs(i, 1, -1);
  }
  printf(f ? "Yes\n" : "No\n");
}
