def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x,y): x = root(x) y = root(y) if x == y: return if x > y: x,y = y,x P[x] += P[y] P[y] = x def same(x,y): return root(x) == root(y) def size(x): x = root(x) return -P[x] MOD = 998244353 N,M = map(int,input().split()) A = list(map(int,input().split())) UV = [list(map(int,input().split())) for _ in range(M)] P = [-1] * N for u,v in UV: unite(u-1,v-1) from collections import defaultdict dic = defaultdict(int) for i,a in enumerate(A): dic[root(i)] += a dic[root(i)] %= MOD ans = 1 for i in range(N): ans *= dic[root(i)] ans %= MOD print(ans)