#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>=1; return r; } ll det_mo(int N) { int x,y,z; ll ret=1; FOR(y,N) FOR(z,N) mat[y][z]=((mat[y][z]%mo)+mo)%mo; FOR(x,N) { vector V; for(y=x;y>N>>M; FOR(i,N) { FOR(j,N) edge[i][j]=-1; in[i]=out[i]=N; edge[i][i]=N-1; } FOR(i,M) { cin>>x>>y; x--,y--; out[x]--; in[y]--; edge[x][y]++; edge[y][y]--; } x=0; st=en=-1; FOR(i,N) { if(in[i]==0 && out[i]==0) id[i]=-1; else id[i]=x, rid[x]=i, x++; if(abs(in[i]-out[i])>1) return _P("0\n"); if(in[i]==out[i]+1) { if(en!=-1) return _P("0\n"); en=i; } if(out[i]==in[i]+1){ if(st!=-1) return _P("0\n"); st=i; } } if(x==0 || x==1) return _P("1\n"); ll pat=(N*N-M)%mo; N=x; if(st>=0) { // odd in[st]++; out[en]++; edge[en][st]--; edge[st][st]++; pat=1; } FOR(i,N) pat = pat*fact[in[rid[i]]-1]%mo; FOR(i,N) FOR(j,N) mat[i][j]=edge[rid[i]][rid[j]]; cout<<(pat*det_mo(N-1)%mo)<