from collections import defaultdict,deque Mod=998244353 N,M=map(int,input().split()) A=list(map(int,input().split())) G=defaultdict(list) for i in range(M): u,v=map(int,input().split()) G[u].append(v) G[v].append(u) C=[0]*(N+1) color_sum=[0]*(N+1) T=1 c=1 while T<=N: que=deque([T]) C[T]=c while len(que): p=que.popleft() for q in G[p]: if(C[q]==0): C[q]=C[p] que.append(q) while T<=N and C[T]!=0: T+=1 c+=1 for i in range(1,N+1): color_sum[C[i]]+=A[i-1] ans=1 # print(color_sum,C) for i in range(1,N+1): ans*=color_sum[C[i]] ans%=Mod print(ans)