def op(x, y): return x+y class UnionFind: def __init__(self, n, A, op): self.n = n self.parent_size = [-1]*n self.A = A[:] self.op = op def leader(self, a): if self.parent_size[a] < 0: return a self.parent_size[a] = self.leader(self.parent_size[a]) return self.parent_size[a] def merge(self, a, b): x, y = self.leader(a), self.leader(b) if x == y: return l, r = self.A[x], self.A[y] if abs(self.parent_size[x]) < abs(self.parent_size[y]): x, y = y, x self.parent_size[x] += self.parent_size[y] self.parent_size[y] = x self.A[x] = self.op(l, r) return def __getitem__(self, n): return self.A[self.leader(n)] def update(self, n, a): self.A[self.leader(n)] = a def same(self, a, b): return self.leader(a) == self.leader(b) def size(self, a): return abs(self.parent_size[self.leader(a)]) def groups(self): result = [[] for _ in range(self.n)] for i in range(self.n): result[self.leader(i)].append(i) return [r for r in result if r != []] N, M = map(int, input().split()) A = list(map(int, input().split())) edge = [list(map(int, input().split())) for _ in range(M)] MOD = 998244353 UF = UnionFind(N, A, op) for U, V in edge: UF.merge(U-1, V-1) ans = 1 for i in range(N): ans *= UF[i] ans %= MOD print(ans)