#include using namespace std; using ll = long long; using ld = long double; //only for atcoder #include using namespace atcoder; #define rep(i,l,r) for(ll i=(l); i<(r); i++) #define rrep(i,l,r) for(ll i=(r)-1; i>=(l); i--) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define REV(c) reverse(ALL(c)) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MINV(c) *min_element(ALL(c)) #define MAXV(c) *max_element(ALL(c)) template void print(TYPE vec){ rep(i,0,vec.size()){ cout << vec[i]; if(i == vec.size()-1){ cout << endl; } else{ cout << " "; } } } using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VS = vector; using VVS = vector; using VB = vector; using VVB = vector; using VC = vector; using VVC = vector; using VD = vector; using VVD = vector; using P = pair; using VP = vector

; using VVP = vector; const ll LINF = 2e18; const int INF = 2e9; using mint = modint998244353; int main(){ int N, M; cin >> N >> M; VL vec(N); rep(i,0,N){ cin >> vec[i]; } VL sum = vec; dsu D(N); rep(i,0,M){ int a, b; cin >> a >> b; a--; b--; if(D.same(a,b)){ continue; } int x = D.leader(a); int y = D.leader(b); D.merge(a,b); int z = D.leader(a); sum[z] = sum[x] + sum[y]; } mint ans = 1; rep(i,0,N){ if(D.leader(i) == i){ int s = D.size(i); rep(j,0,s){ ans *= sum[i]; } } } cout << ans.val() << endl; }