MOD = 998244353 class UnionFind: def __init__(self, n, data): self.n = n self.par = [-1] * n self.d = list(data) def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x self.d[x] += self.d[y] if self.d[x] >= MOD: self.d[x] -= MOD def size(self, x): return -self.par[self.find(x)] def data(self, x): return self.d[self.find(x)] n, m = map(int, input().split(" ")) a = list(map(int, input().split(" "))) uf = UnionFind(n, a) for _ in range(m): u, v = map(int, input().split(" ")) uf.unite(u - 1, v - 1) ans = 1 for x in range(n): if uf.find(x) != x: continue c = uf.size(x) s = uf.data(x) for _ in range(c): ans = ans * s % MOD print(ans)