#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N,M; vector<pair<ull,int>> G; vector<int> ans; int main(){ scanf("%d%d",&N,&M); G.resize(M); rep(i,M){ int a; scanf("%d",&a); G[i].first=0; rep(j,a){ int b; scanf("%d",&b); b--; G[i].first|=(1ull<<b); } scanf("%d",&G[i].second); } ans.resize(N); int p=0; rep(i,N){ if(p>=M) continue; for(int j=p+1; j<M; j++) if((G[j].first>>i)&1) swap(G[j],G[p]); if((G[p].first>>i)&1){ for(int j=0; j<M; j++) if(j!=p) if((G[j].first>>i)&1){ G[j].first^=G[p].first; G[j].second^=G[p].second; } p++; } } for(int j=p; j<M; j++) if(G[j].second!=0){ printf("-1\n"); return 0; } rep(i,p){ rep(d,N) if((G[i].first>>d)&1){ ans[d]=G[i].second; break; } } rep(i,N) printf("%d\n",ans[i]); return 0; }