#include <bits/stdc++.h>
using namespace std;

typedef double lf; typedef long long ll; typedef vector<ll> vll; typedef long double llf; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef unsigned int uint; typedef pair<int, int> pii; typedef unsigned long long ull;

bool Dbg;
const int mod = 998244353, MAXN = 1e5 + 7, inft = 1e9 + 7; const ll infl = llf(1e18) + 1;
const llf eps = 1e-7;

#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define mid ((l+r)>>1)
//ans = mid, l = mid+1
#define Debug(x) (Dbg ? void(cerr << #x << " = " << x << ' ') : void())
#define debug(...) (Dbg ? (fprintf(stderr, __VA_ARGS__)) : 0)
#define lop(i,a,b) for(int i = (a), i##end = (b); i <= i##end; ++i)
//toposort
#define dlop(i,a,b) for(int i = (a), i##end = (b); i >= i##end; --i)
#define ergo(a) for(__typeof((a).end())it = (a).begin(), it##end = (a).end(); it != it##end; ++it)

template<typename T> inline T sqr(T x) {return x * x; }
template<typename T> inline T abs(T x) {return x >= 0 ? x : -x; }
template<typename A, typename B> inline A gcd(A a, B b) {if (a < b) swap(a, b); if (!b) return a; while (A t = a % b) a = b, b = t; return b; }
template<typename A, typename B> inline A lcm(A a, B b) {return a / gcd(a, b) * b; }
template<typename A, typename B> inline A Pow(A a, B b, int mod) {A ret; for (ret = 1; b; b >>= 1) {if (b & 1) ret = ret * 1ll * a % mod; a = a * 1ll * a % mod; } return ret % mod; }
template<typename A, typename B> inline A max(A a, B b) {return a > b ? a : b; } template<typename A, typename B> inline A min(A a, B b) {return a < b ? a : b; } template<typename A, typename B> inline void chmax(A &x, B y) {if (x < y) x = y; } template<typename A, typename B> inline void chmin(A &x, B y) {if (x > y) x = y; } template<typename A, typename B> inline void amod(A &x, B y) {x += y; while (x < 0) x += mod; while (x > mod) x -= mod; }

struct IO {
#define IS(x) (x == 10 || x == 13 || x == ' ')
#define OP operator
#define RT return *this
#define RX x=0;int t=P();while((t<'0'||t>'9')&&t!='-')t=P();f=1;\
  if(t=='-')t=P(),f=-1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RU x=0;int t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x
#define WI if(x){if(x<0)P('-'),x=-x;c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WU if(x){c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
  struct Cg {inline int operator()() {return getchar(); } }; struct Cp {inline void operator()(int x) {putchar(x); } }; template<typename T>struct Fr {int f; T P; inline Fr&OP, (int&x) {RX; x *= f; RT; } inline Fr&OP, (ll &x) {RX; x *= f; RT; } inline Fr&OP, (char&x) {for (x = P(); IS(x); x = P()); RT; } inline Fr&OP, (string&x) {cin >> x; RT; } inline Fr&OP, (char*x) {char t = P(); for (; IS(t); t = P()); if (~t) {for (; !IS(t) && ~t; t = P()) * x++ = t; }*x++ = 0; RT; } inline Fr&OP, (lf&x) {scanf("%lf", &x); RT; } inline Fr&OP, (llf&x) {lf y; scanf("%lf", &y); x = y; RT; } inline Fr&OP, (uint&x) {RU; RT; } inline Fr&OP, (ull&x) {RU; RT; } }; Fr<Cg>in; template<typename T>struct Fw {int c, s[24]; T P; inline Fw&OP, (int x) {WI; RT; } inline Fw&OP, (uint x) {WU; RT; } inline Fw&OP, (ll x) {WI; RT; } inline Fw&OP, (ull x) {WU; RT; } inline Fw&OP, (char x) {P(x); RT; } inline Fw&OP, (lf x) {printf("%.5lf", x); RT; } inline Fw&OP, (llf x) {printf("%.5lf", lf(x)); RT; } inline Fw&OP, (const string &x) {ergo(x) P(*it); RT; } inline Fw&OP, (const char*x) {while (*x)P(*x++); RT; } }; Fw<Cp>out;
} io;
#define in io.in
#define out io.out
//fread float

vector<int>G[MAXN << 2];
int n, m;
int vis[MAXN << 2], col[MAXN << 1];
inline void add(int u, int v, int w) {
  if (w) G[u].pb(v + n), G[v].pb(u + n);
  else G[u + n].pb(v), G[v + n].pb(u);
}

inline void bfs(int s) {
  queue<int>q; q.push(s);
  col[s] = 0;
  while (!q.empty()) {
    int u = q.front(); q.pop();
    ergo(G[u]) {
      if (col[*it] == col[u]) {
        // cerr << u << ' ' << *it << endl;
        puts("Yes");
        exit(0);
      }
      col[*it] = !col[u], q.push(*it);
    }
  }
}
void DFS(int u) {
  col[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (col[v] == 0)
      DFS(v);
    if (col[v] == 1) {
      printf("Yes\n");
      exit(0);
    }
  }
  col[u] = -1;
}
int main() {
#ifdef LOCAL_DEBUG
  // freopen("data.in", "r", stdin), freopen("data.out", "w", stdout);
  Dbg = 1;
  uint tim1 = clock();
#endif
  in, n, m;
  lop(i, 1, n) {
    char s; in, s;
    if (s == 'B') col[i] = 1;
  }
  while (m--) {
    int u, v;
    in, u, v;
    if (col[u] == col[v]) {
      G[u].push_back(v + n);
      G[v].push_back(u + n);
    }
    else {
      G[u + n].push_back(v);
      G[v + n].push_back(u);
    }
    // add(u, v, col[u] == col[v]);
  }
  fill(col + 1, col + 1 + n, 0);
  lop(i, 1, n) if (col[i] == 0) DFS(i);
  puts("No");

#ifdef LOCAL_DEBUG
  fprintf(stderr, "\ntime:%.5lfms", (clock() - tim1) / (1.0 * CLOCKS_PER_SEC) * 1000);
#endif
  return 0;
}
/*
*/

Measured memory_bytes: 26752