#include #include #include #define int long long struct uf{ std::vector r; uf(int n):r(std::vector(n, -1)){}; void change(int u, int val){ r[u] = -val; } int root(int u){ if(r[u]<0){ return u; } else{ return r[u] = root(r[u]); } } int size(int u){ return -r[root(u)]; } bool connect(int a,int b){ if(size(a) < size(b)){ std::swap(a,b); } if(root(a) == root(b)){ return false; } a = root(a); b = root(b); r[a] += r[b]; r[b] = a; return true; } }; signed main(void){ int n,m; std::cin>>n>>m; uf g(n); for(int i = 0; i < n; i++){ int a;std::cin>>a; g.change(i, a); } while(m--){ int u,v; u--;v--; g.connect(u,v); } int res = 1; for(int i=0; i < n; i++){ res *= g.size(i) % 998244353; res %= 998244353; } std::cout << res << std::endl; }