#include #include int check[110]; int x[10010][110]; int y[10010]; int main() { int a,b; scanf("%d%d",&a,&b); for(int i=1;i<=b;i++) { int c; scanf("%d",&c); for(int j=1;j<=c;j++) { int d; scanf("%d",&d); x[i][d] = 1; } scanf("%d",&y[i]); } for(int i=1;i<=b;i++) { for(int j=1;j<=a;j++) { if(x[i][j]==1) { for(int k=1;k<=b;k++) { if(k==i) continue; if(x[k][j]==1) { for(int l=1;l<=a;l++) x[k][l] ^= x[i][l]; y[k] ^= y[i]; } } goto u; } } if(y[i]!=0) { printf("-1"); return 0; } u:; } for(int i=1;i<=a;i++) check[i] = -1; for(int i=b;i>=1;i--) { std::vector temp; for(int j=1;j<=a;j++) { if(x[i][j]==1) { if(check[j]==-1) temp.push_back(j); else y[i] ^= check[j]; } } if(!temp.empty()) { check[temp[0]] = y[i]; for(int j=1;j