#include #include #include #include #include #include #include using namespace std; using ll = long long; struct P { P &operator^=(const P &p) { b ^= p.b; y ^= p.y; return *this; } ll b; int y; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector

p(m); for (int i = 0; i < m; i++) { int a; cin >> a; ll b = 0; for (int j = 0; j < a; j++) { int k; cin >> k; k--; b ^= 1LL << k; } int y; cin >> y; p[i] = { b, y }; } for (int k = 0; k < n; k++) { ll t = 1LL << (n - 1 - k); int f = 0; for (int i = k; i < m; i++) { if (p[i].b & t) { for (int i1 = i + 1; i1 < m; i1++) { p[i1] ^= p[i]; } swap(p[i], p[k]); f = 1; break; } } if (f == 0) { p.push_back({ t, 0 }); m++; swap(p.back(), p[k]); } } for (int i = 0; i < m; i++) { if (p[i].b == 0 && p[i].y != 0) { cout << -1 << endl; exit(0); } } for (int i = n; --i >= 0;) { for (int i1 = 0; i1 < i; i1++) { if (p[i].b & p[i1].b) { p[i1] ^= p[i]; } } } for (int i = 0; i < n; i++) { cout << p[n - 1 - i].y << '\n'; } return 0; }