#include <bits/stdc++.h>
using namespace std;
int label[200001];
set<int> adj[200001];
vector<int> vec[200001];
int nvis[200001], vis[200001];
int status[200001];
int badhiya[200001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string str;
  cin >> str;
  for (int i = 0; i < n; i++) {
    label[i] = (str[i] == 'A');
  }
  int a, b;
  vector<int> black;
  bool f = false;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    --a;
    --b;
    if (a == b) badhiya[a] = 1, badhiya[b] = 1;
    if (label[a] != label[b] && badhiya[a] && badhiya[b]) {
      f = true;
      break;
    }
    adj[a].insert(b);
    adj[b].insert(a);
    if (str[a] == 'B') black.push_back(a);
  }
  if (f) {
    cout << "Yes" << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (auto it : adj[i]) {
      if (label[i] != label[it] && badhiya[i] && badhiya[it]) {
        cout << "Yes" << '\n';
        return 0;
      }
      if (!vis[it] && label[i] == label[it]) {
        int c = 0;
        for (auto itr : black) {
          if (adj[itr].find(i) != adj[itr].end() &&
              adj[itr].find(it) != adj[itr].end()) {
            c++;
            if (badhiya[i] || badhiya[it]) c++;
          }
          if (c == 2) {
            cout << "Yes" << '\n';
            return 0;
          }
        }
      }
    }
    vis[i] = 1;
  }
  cout << "No" << '\n';
  return 0;
}
