#include <bits/stdc++.h>
using namespace std;
int n, m;
char arr[200005], ch[200005];
int active[200005];
vector<vector<int>> g;
bool find(int u, int act) {
  if (active[u] == act) return ch[u];
  active[u] = act;
  bool a = 0, b = 0;
  for (int i = 0; i < g[u].size(); ++i) {
    int node = g[u][i];
    if (arr[node] == 'A' && !a) {
      a = find(node, act);
    } else if (arr[node] == 'B' && !b) {
      b = find(node, act);
    }
  }
  ch[u] = a && b;
  return a && b;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; ++i) {
    if (find(i, i)) return cout << "Yes" << endl, 0;
  }
  cout << "No" << endl;
  return 0;
}
