#include using namespace std; #include using namespace atcoder; using mint = modint998244353; typedef long long ll; typedef unsigned long long ull; const int MAX = 1e9; const int MIN = -1*1e9; const ll MAXLL = 1e18; const ll MINLL = -1*1e18; //const ll MOD = 998244353; //const ll MOD = 1000000007; vector> G(200010); vector F(200010); vector Path; void DFS(int N) { Path.push_back(N); F[N] = true; for(auto x : G[N]) { if(!F[x]) DFS(x); } return; } int main() { int N,M; cin >> N >> M; vector V(N+1); for(int i = 1; i <= N; i++) { cin >> V[i]; } for(int i = 0; i < M; i++) { int A,B; cin >> A >> B; G[A].push_back(B); G[B].push_back(A); } mint Ans = 1; for(int i = 1; i <= N; i++) { if(!F[i]) { Path.clear(); DFS(i); ll Count = 0; for(auto x : Path) { Count += V[x]; } for(int j = 0; j < Path.size(); j++) Ans *= Count; } } cout << Ans.val() << endl; return 0; }