#include <bits/stdc++.h> 
#define Rint register int
#define LL long long
#define F(x,y,z) for(Rint x=y;x<=z;++x)
#define D(x,y,z) for(Rint x=y;x>=z;--x)
using namespace std;
LL Min(LL x,LL y){return x<y?x:y;}
LL Max(LL x,LL y){return x>y?x:y;}
inline LL R(){
    char c='!';LL x=0,z=1;
    for( ; c>'9'||c<'0';c=getchar()) if(c=='-')z=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
    return x*z;
}
const int N=400010;
int n,m,countt;
char s[200010];
int to[N],ne[N],st[N],sl;
int ys[N],cnta,cntb,a[N],b[N];
bitset<100010> p[200010],b1,b2;
void Ads(int x,int y){
	to[++sl]=y;ne[sl]=st[x];st[x]=sl;
}

int main(){
	n=R();m=R();
	cin>>s;
	D(i,n,1)s[i]=s[i-1];
	F(i,1,n) countt+=s[i]=='B';
	if (countt>100000)
		F(i,1,n) s[i]=s[i]=='A'?'B':'A';
	F(i,1,n) if (s[i]=='A') ys[i]=++cnta;else ys[i]=++cntb;
	F(i,1,m){
		int x=R(),y=R();
		a[i]=x;b[i]=y;
		Ads(x,y);Ads(y,x);
	}
	F(u,1,n){
		if (s[u]=='A') continue;
		for (int i=st[u];i;i=ne[i])
			if (s[to[i]]=='A')p[ys[u]][ys[to[i]]]=1;
	}
	F(i,1,m)
		if (s[a[i]]=='B'&&s[b[i]]=='B'){
			b1=p[ys[a[i]]]&p[ys[b[i]]];
			if (!b1.none()){
				printf("Yes\n");
				return 0;
			}
		}
	printf("No\n");
	return 0;
}