#include using namespace std; #include #include using namespace atcoder; using mint=modint998244353; int main(void) { int n; cin >> n; int m; cin >> m; vector t(m); vector> s(m); vector a(n); for(int i=0;i> t[i]; s[i].resize(t[i]); for(int j=0;j> s[i][j]; --s[i][j]; } int tmp=a[s[i][t[i]-1]]; for(int j=t[i]-1;j>0;--j){ a[s[i][j]]=a[s[i][j-1]]; } a[s[i][0]]=tmp; } dsu g(n); for(int i=0;i e; for(auto group: groups){ int s=group.size(); int p=0; while(s%2==0){ ++p; s/=2; } if(p>e[2]){ e[2]=p; } for(int i=3;i*ie[i]){ e[i]=p; } } if(s>1 && e[s]==0){ e[s]=1; } } ans*=mint(2).pow(e[2]); for(int i=3;i<=n;i+=2){ ans*=mint(i).pow(e[i]); } cout << ans.val() << endl; return 0; }