N, M = [int(i) for i in input().split(' ')]
import sys
from collections import defaultdict
sys.setrecursionlimit(100000)

s = input().strip()
ds = [defaultdict(set), defaultdict(set)]
starts = set()
for ll in sys.stdin:
    i, j = ll.strip().split(' ')
    i, j = int(i)-1, int(j)-1
    ds[0 if s[i] == s[j] else 1][str(0 if s[i] == s[j] else 1) + str(i)].add(str(1 if s[i] == s[j] else 0) + str(j))
    ds[0 if s[i] == s[j] else 1][str(0 if s[i] == s[j] else 1) + str(j)].add(str(1 if s[i] == s[j] else 0) + str(i))
    if s[i] == 'A' and s[j] == 'A':
        starts.add(str(0)+str(i))


checked = set()

path = set()
#path = []

def walk(i, depth):
    dd = ds[depth]
    checked.add(i)
    if len(dd[i]) == 0:
        return False
    r = False
    for item in dd[i]:
        if item in path:
            return True
        if item not in checked:
            path.add(item)
#            path.append(item)
            r = r or walk(item, (depth+1) % 2)
            path.remove(item)
#            path.pop()
    return r

result = False
for item in starts:
    if item not in checked:
        path.add(item)
#        path.append(item)
        result = result or walk(item, 0)
        path.remove(item)
#        path.pop()
if result:
    print('Yes')
else:
    print('No')
