#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll li
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000000000000
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll> 
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 2000010
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
 
 
// #define INTMAX 200000000 
 
// using namespace boost;
// #define si short int
 
using namespace std;
using namespace __gnu_pbds;             
typedef priority_queue<pii, vector<pii> ,greater < pii > > min_pq;
// typedef priority_queue<pii, vector<pii> , greater<pii >  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}
 
// using namespace __gnu_pbds;         
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define nn 2000005
ll n,m;
string s;
bool visited[ N ];
ll mark[ N ];
bool poss[ N ];
ll df[ N ];
bool ans = 0;
ll mark2[ N ];
vector < list < ll > > adjlist ( N );
set < pii > g;
ll dega[ N ],degb[ N ];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    cin >> s;
    vector < ll > stdfs;
    for ( ll i = 1; i<= m; i ++)
    {
        ll a,b;
        cin >> a >> b;
        g.insert(mp(min(a,b),max(a,b)));
    }
    for ( auto it : g )
    {
        ll a,b;
        a = it.fi;
        b = it.sec;
        if ( a == b )
        {
            stdfs.pb(a);
            mark[a]=1;
            if ( s[a-1]=='B')
                degb[a]++;
            else
                dega[a]++;
            continue;
        }
        if ( s[b-1] == 'B')
            degb[a]++;
        else
            dega[a]++;
        if ( s[a-1] == 'B')
            degb[b]++;
        else
            dega[b]++;
        // deg[b]++;
        adjlist[a].pb(b);
        adjlist[b].pb(a);
        // trace(dega[a],dega[b]);
    }
    
    for ( ll i =1 ; i <= n; i ++)
    {
        set < char > st;
        if ( mark[i] )
            st.insert(s[i-1]);
        for ( auto neig : adjlist[i] )
            st.insert(s[neig-1]);
        if ( st.size() == 2 )
        {
            df[i]=1;
        }
    }
    set < ll > st;
    for ( ll i = 1; i <= n; i++)
        st.insert(i);
    queue < ll > q;
    for ( ll i = 1; i <= n; i ++)
    {
        if ( !df[i] )
        {
            // trace(i);
            q.push(i);
            st.erase(i);
        }
    }
    // trace(dega[4]);
    while(!q.empty())
    {
        ll p = q.front();
        // trace(p);
        q.pop();
        for ( auto it : adjlist[p] )
        {
            if ( st.find(it)!=st.end() )
            {
                // trace(it);
                if ( s[p-1]=='A')
                    dega[it]--;
                if ( s[p-1]=='B')
                    degb[it]--;
                if ( dega[it]<=0  or degb[it]<=0)
                {
                    st.erase(it);
                    q.push(it);
                }
            }
        }
    } 
    if ( st.size() )
        cout <<"Yes";
    else
        cout <<"No";
}

Measured memory_bytes: 78800