#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, m;
string s;
vector<int> E[MAXN];
int a[MAXN], b[MAXN];
bool da[MAXN], bio[MAXN];
void bfsSz(int start) {
  if (bio[start]) return;
  queue<pair<int, int> > Q;
  Q.push(pair<int, int>(start, 1));
  while (!Q.empty()) {
    pair<int, int> x = Q.front();
    Q.pop();
    if (x.second == 4 &&
        find(E[x.first].begin(), E[x.first].end(), start) != E[x.first].end()) {
      cout << "Yes";
      exit(0);
    }
    if (x.second == 4) continue;
    for (int it : E[x.first]) {
      if (da[it]) {
        if (x.second == 2 || x.second == 3) {
          if (s[start] != s[it]) Q.push(pair<int, int>(it, x.second + 1));
        } else if (s[start] == s[it])
          Q.push(pair<int, int>(it, x.second + 1));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  cin >> s;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    if (a[i] == b[i])
      E[a[i]].push_back(a[i]);
    else {
      E[a[i]].push_back(b[i]);
      E[b[i]].push_back(a[i]);
    }
  }
  for (int i = 0; i < n; ++i) {
    bool A, B;
    A = B = false;
    for (auto it : E[i]) {
      int val = s[it] == 'B';
      if (!val)
        A = true;
      else
        B = true;
    }
    if (A & B) da[i] = true;
  }
  for (int j = 0; j < 5; ++j)
    for (int i = 0; i < n; ++i) {
      bool A, B;
      A = B = false;
      for (auto it : E[i]) {
        if (!da[it]) continue;
        int val = s[it] == 'B';
        if (!val)
          A = true;
        else
          B = true;
      }
      if (A & B)
        da[i] = true;
      else
        da[i] = false;
    }
  for (int i = 0; i < n; ++i)
    if (da[i]) bfsSz(i);
  cout << "No";
}
