from collections import deque class Node(): def __init__(self, x): self.id = x self.connect = [] def bfs(start: int, nodes: list, t: list, visited: list) -> bool: q = deque() q.append(start) visited[start] = True while q: cur = q.popleft() if cur == len(t): # 到达编号为 n 的节点 return True for e in nodes[cur].connect: if not visited[e] and t[e - 1] == 0: visited[e] = True q.append(e) return False n, m = map(int, input().split()) nodes = [Node(i) for i in range(n + 1)] t = list(map(int, input().split())) for _ in range(m): a, b = map(int, input().split()) nodes[a].connect.append(b) nodes[b].connect.append(a) visited = [False] * (n + 1) if bfs(1, nodes, t, visited): print("Yes") else: print("No")