output_description: If Nusook can make all strings consisting of `A` and `B`, print `Yes`;
  otherwise, print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      s
      a_1 b_1
      :
      a_{M} b_{M}
attempt: """
  https://beta.atcoder.jp/contests/agc027/submissions/3201641
  """
  
  n, m = map(int, input().split())
  s = list(input())
  
  deg = [{"A": 0, "B": 0} for _ in range(n)]  # deg[0 - (n - 1)][0 - 1] = 0
  g = [list() for _ in range(n)]  # g[0 - (n - 1)] = []
  
  for i in range(m):  # クエリを配列に代入
      x, y = map(int, input().split())
      x, y = x - 1, y - 1  # 1-indexed -> 0-indexed
      deg[x][
          s[y]
      ] += 1  # 頂点 x に隣接する頂点の個数を管理 : A か B かに応じて, その文字のカウントを 1 増やす
      deg[y][
          s[x]
      ] += 1  # 頂点 y に隣接する頂点の個数を管理 : A か B かに応じて, その文字のカウントを 1 増やす
      g[x].append(y)  # 頂点 x に隣接する頂点のリストに y を追加
      g[y].append(x)  # 頂点 y に隣接する頂点のリストに x を追加
  
  was = [False for _ in range(n)]  # was[j] = True なら 頂点 j は que に追加済み
  que = []  # A か B が隣接しないため, 連結リストから除外する頂点
  
  for i in range(n):  # 全頂点をループ
      if deg[i]["A"] == 0 or deg[i]["B"] == 0:  # A か B が隣接しないなら
          que.append(i)  # 除外頂点リスト que に追加
          was[i] = True  #  was[j] = True は, 除外頂点リスト que に追加済を意味する
  
  for (
      q
  ) in (
      que
  ):  # A か B が隣接していない, 除外頂点リストの各頂点をループ（ que はループ中に追加されうる）
      for j in g[q]:  # 除外頂点に隣接する頂点をループ
          deg[j][
              s[q]
          ] -= 1  # "除外頂点に隣接する頂点" に隣接する頂点の個数を管理 : 除外頂点の文字のカウントを減らす
          if (
              deg[j]["A"] == 0 or deg[j]["B"] == 0
          ):  # "除外頂点に隣接する頂点" に A か B が隣接しないなら
              if not was[
                  j
              ]:  # 頂点 j が que に追加済みの頂点でないなら, que に追加する / 追加済みなら, 隣接する頂点の個数管理は, 終了済み
                  was[j] = True
                  que.append(j)  # 除外頂点リスト que に追加, ループ回数増える
  
  # 除外頂点を取り除いた後に, 頂点が残っていれば, AABB... を作成できる
  # 頂点が残っていなければ, つまり, que に全ての頂点が入っていれば, AABB...を作成できない
  print("No" if len(que) == n else "Yes")
  
problem_description: Statement
  
  You are given an undirected graph consisting of N vertices and M edges. The
  vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition,
  each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i
  bidirectionally connects vertex a_i and b_i.
  
  The phantom thief Nusook likes to choose some vertex as the startpoint and
  traverse an edge zero or more times. Today, he will make a string after
  traveling as above, by placing the labels of the visited vertices in the order
  visited, beginning from the startpoint.
  
  For example, in a graph where Vertex 1 has the label `A` and Vertex 2 has the
  label `B`, if Nusook travels along the path 1 \rightarrow 2 \rightarrow 1
  \rightarrow 2 \rightarrow 2, the resulting string is `ABABB`.
  
  Determine if Nusook can make all strings consisting of `A` and `B`.
samples: [{"input": "2 3\n    AB\n    1 1\n    1 2\n    2 2", "output": "Yes\n    \n\n  * Since Nusook can visit Vertex 1 and Vertex 2 in any way he likes, he can make all strings consisting of `A` and `B`.\n\n![77e96cf8e213d606ddd8f3c3f8315d32.png](https://img.atcoder.jp/agc027/77e96cf8e213d606ddd8f3c3f8315d32.png)\n\n* * *"}, {"input": "4 3\n    ABAB\n    1 2\n    2 3\n    3 1", "output": "No\n    \n\n  * For example, Nusook cannot make `BB`.\n  * The given graph may not be connected.\n\n![1ab1411cb9d6ee023d14ca4e77c4b584.png](https://img.atcoder.jp/agc027/1ab1411cb9d6ee023d14ca4e77c4b584.png)\n\n* * *"}, {"input": "13 23\n    ABAAAABBBBAAB\n    7 1\n    10 6\n    1 11\n    2 10\n    2 8\n    2 11\n    11 12\n    8 3\n    7 12\n    11 2\n    13 13\n    11 9\n    4 1\n    9 7\n    9 6\n    8 13\n    8 6\n    4 10\n    8 7\n    4 3\n    2 1\n    8 12\n    6 9", "output": "Yes\n    \n\n* * *"}, {"input": "13 17\n    BBABBBAABABBA\n    7 1\n    7 9\n    11 12\n    3 9\n    11 9\n    2 1\n    11 5\n    12 11\n    10 8\n    1 11\n    1 8\n    7 7\n    9 10\n    8 8\n    8 12\n    6 2\n    13 11", "output": "No"}]