#include using namespace std; int main(){ int N, M; cin >> N >> M; vector> S(M, vector(N + 1, 0)); for (int i = 0; i < M; i++){ int A; cin >> A; for (int j = 0; j < A; j++){ int B; cin >> B; B--; S[i][B] = 1; } cin >> S[i][N]; } int c = 0; vector id; for (int i = 0; i < N; i++){ int p = c; for (int j = c; j < M; j++){ if (S[j][i] == 1){ p = j; } } swap(S[c], S[p]); if (S[p][i] > 0){ c++; for (int j = 0; j < M; j++){ if (j != p && S[j][i] == 1){ for (int k = 0; k <= N; k++){ S[j][k] ^= S[p][k]; } } } id.push_back(i); } if (c == M){ break; } } int cnt = id.size(); vector X(N, 0); for (int i = 0; i < cnt; i++){ X[id[i]] = S[i][N]; } bool ok = true; for (int i = 0; i < M; i++){ int s = 0; for (int j = 0; j < N; j++){ if (S[i][j] == 1){ s ^= X[j]; } } if (s != S[i][N]){ ok = false; } } if (!ok){ cout << -1 << endl; } else { for (int i = 0; i < N; i++){ cout << X[i] << endl; } } }