#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i par; UnionFind(int n) :par(n, -1) { } void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool connect(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; UnionFind uf(n); rep(i, m) { int x, y; cin >> x >> y; x --; y --; uf.connect(x, y); } ll ans = 1; vector num(n, -1); rep(i, n) { int r = uf.root(i); if(num[r] != -1) { ans *= num[r]; ans %= MOD998; } else { ll s = 0; rep(j, n) if(uf.root(j) == r) s += a[j]; s %= MOD998; num[r] = s; ans *= s; ans %= MOD998; } } cout << ans << endl; return 0; }