import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd from collections import defaultdict class UnionFind: def __init__(self, n): self.n = n self.p = [-1] * (n+1) def find(self, x): if self.p[x] < 0: return x else: self.p[x] = self.find(self.p[x]) return self.p[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.p[x] > self.p[y]: x, y = y, x self.p[x] += self.p[y] self.p[y] = x def same(self, a, b): return self.find(a) == self.find(b) def group(self): d = defaultdict(list) for i in range(1, self.n+1): par = self.find(i) d[par].append(i) return d mod = 998244353 n,m = map(int,input().split()) A = list(map(int,input().split())) uf = UnionFind(n) graph = [[] for i in range(n+1)] for i in range(m): a,b = map(int,input().split()) graph[a].append(b) graph[b].append(a) uf.union(a,b) g = uf.group() tot = [0]*(n+1) for k,v in g.items(): tmp = 0 for i in v: tmp += A[i-1] tmp %= mod for i in v: tot[i] = tmp ans = 1 for i in range(1, n+1): ans *= tot[i] ans %= mod print(ans)