import sys

from collections import deque

N,M=list(map(int,input().split()))

s=eval(input())

table=[]

for i in range(M):

    x,y=list(map(int,input().split()))

    table.append((x-1,y-1))

edge=[[]for i in range(2*N)]

visit=[0]*(2*N)

for x,y in table:

    if x==y:

        edge[2*x].append(2*x+1)

        visit[2*x+1]+=1

        continue

    if s[x]==s[y]:

        edge[2*x].append(2*y+1)

        edge[2*y].append(2*x+1)

        visit[2*x+1]+=1

        visit[2*y+1]+=1

        continue

    edge[2*x+1].append(2*y)

    edge[2*y+1].append(2*x)

    visit[2*x]+=1

    visit[2*y]+=1

S=set()

L=deque()



for i in range(2*N):

    if visit[i]==0:

        L.append(i)



while L:

    x=L.pop()

    S.add(x)

    for y in edge[x]:

        visit[y]-=1

        if visit[y]==0:

            L.append(y)

if len(S)!=2*N:

    print('Yes')

else:

    print('No')

import sys

from collections import deque

N,M=list(map(int,input().split()))

s=eval(input())

table=[]

for i in range(M):

    x,y=list(map(int,input().split()))

    table.append((x-1,y-1))

A=[0]*N

B=[0]*N

edge=[[] for i in range(N)]

S=[False]*N

L=deque()

for x,y in table:

    if x==y:

        #edge[x].append(y)

        if s[x]=='A':

            A[x]+=1

        else:

            B[x]+=1

        continue

    edge[x].append(y)

    edge[y].append(x)

    if s[x]=='A':

        A[y]+=1

    else:

        B[y]+=1

    if s[y]=='A':

        A[x]+=1

    else:

        B[x]+=1 

        

for i in range(N):

    if A[i]*B[i]==0:

        L.append(i)

        S[i]=True



while L:

    x=L.pop()

    t=s[x]

    for y in edge[x]:

        if S[y]:

            continue

        if t=='A':

            A[y]-=1

        else:

            B[y]-=1

        if A[y]*B[y]==0:

            L.append(y)

            S[y]=True

if sum(S)!=N:

    print('Yes')

else:

    print('No')

import sys
from collections import deque

N, M = list(map(int, input().split()))
s = eval(input())
table = []
for i in range(M):
    x, y = list(map(int, input().split()))
    table.append((x - 1, y - 1))
edge = [[] for i in range(2 * N)]
visit = [0] * (2 * N)
for x, y in table:
    if x == y:
        edge[2 * x].append(2 * x + 1)
        visit[2 * x + 1] += 1
        continue
    if s[x] == s[y]:
        edge[2 * x].append(2 * y + 1)
        edge[2 * y].append(2 * x + 1)
        visit[2 * x + 1] += 1
        visit[2 * y + 1] += 1
        continue
    edge[2 * x + 1].append(2 * y)
    edge[2 * y + 1].append(2 * x)
    visit[2 * x] += 1
    visit[2 * y] += 1
S = set()
L = deque()
for i in range(2 * N):
    if visit[i] == 0:
        L.append(i)
while L:
    x = L.pop()
    S.add(x)
    for y in edge[x]:
        visit[y] -= 1
        if visit[y] == 0:
            L.append(y)
if len(S) != 2 * N:
    print("Yes")
else:
    print("No")

import sys
from collections import deque

N, M = list(map(int, input().split()))
s = eval(input())
table = []
for i in range(M):
    x, y = list(map(int, input().split()))
    table.append((x - 1, y - 1))
A = [0] * N
B = [0] * N
edge = [[] for i in range(N)]
S = [False] * N
L = deque()
for x, y in table:
    if x == y:
        # edge[x].append(y)
        if s[x] == "A":
            A[x] += 1
        else:
            B[x] += 1
        continue
    edge[x].append(y)
    edge[y].append(x)
    if s[x] == "A":
        A[y] += 1
    else:
        B[y] += 1
    if s[y] == "A":
        A[x] += 1
    else:
        B[x] += 1
for i in range(N):
    if A[i] * B[i] == 0:
        L.append(i)
        S[i] = True
while L:
    x = L.pop()
    t = s[x]
    for y in edge[x]:
        if S[y]:
            continue
        if t == "A":
            A[y] -= 1
        else:
            B[y] -= 1
        if A[y] * B[y] == 0:
            L.append(y)
            S[y] = True
if sum(S) != N:
    print("Yes")
else:
    print("No")

-edge = [[] for i in range(2 * N)] -visit = [0] * (2 * N) +A = [0] * N +B = [0] * N +edge = [[] for i in range(N)] +S = [False] * N +L = deque() -        edge[2 * x].append(2 * x + 1) -        visit[2 * x + 1] += 1 +        # edge[x].append(y) +        if s[x] == "A": +            A[x] += 1 +        else: +            B[x] += 1 -    if s[x] == s[y]: -        edge[2 * x].append(2 * y + 1) -        edge[2 * y].append(2 * x + 1) -        visit[2 * x + 1] += 1 -        visit[2 * y + 1] += 1 -        continue -    edge[2 * x + 1].append(2 * y) -    edge[2 * y + 1].append(2 * x) -    visit[2 * x] += 1 -    visit[2 * y] += 1 -S = set() -L = deque() -for i in range(2 * N): -    if visit[i] == 0: +    edge[x].append(y) +    edge[y].append(x) +    if s[x] == "A": +        A[y] += 1 +    else: +        B[y] += 1 +    if s[y] == "A": +        A[x] += 1 +    else: +        B[x] += 1 +for i in range(N): +    if A[i] * B[i] == 0: +        S[i] = True -    S.add(x) +    t = s[x] -        visit[y] -= 1 -        if visit[y] == 0: +        if S[y]: +            continue +        if t == "A": +            A[y] -= 1 +        else: +            B[y] -= 1 +        if A[y] * B[y] == 0: -if len(S) != 2 * N: +            S[y] = True +if sum(S) != N: