#include #include #include using namespace std; using namespace atcoder; using mint = modint1000000007; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int n,m; vector a,y; vector> b; void Gauss(vector> &B){ int now = 0; rep(i,52){ int temp = -1; for(int j=now;j0){ rep(j,B.back().size()){ if(B.back()[j]!=0)return; } B.pop_back(); } } int main(){ cin>>n>>m; a.resize(m); b.resize(m); y.resize(m); rep(i,m){ cin>>a[i]; b[i].resize(a[i]); rep(j,a[i]){ cin>>b[i][j]; b[i][j]--; } cin>>y[i]; } vector ans(n,0); rep(i,30){ vector> B; rep(j,m){ int ind = -1; bitset<52> bb; rep(k,a[j]){ bb[b[j][k]] = 1; } if((y[j]>>i)&1)bb[51] = 1; B.push_back(bb); } Gauss(B); vector t(n,-1); rep(j,B.size()){ int temp = B[j][51];; vector ind; rep(k,n){ if(B[j][k]){ if(t[k]==-1){ ind.push_back(k); } else{ temp ^= t[k]; } } } if(ind.size()==0 && temp){ cout<<-1<