#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define sz(x) ((ll)(x).size()) #define ceil(x, y) (((x)+(y)-1) / (y)) #define all(x) (x).begin(),(x).end() #define outl(...) dump_func(__VA_ARGS__) #define inf 1e18 #define mod 1000000007 using namespace std; typedef long long llint; typedef long long ll; typedef pair P; bool exceed(ll x, ll y, ll m){return x >= m / y + 1;} template ostream& operator << (ostream& os, vector& vec) { for(int i = 0; i ostream& operator << (ostream& os, pair& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template ostream& operator << (ostream& os, map& map_var) { for(typename map::iterator itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ","; itr--; } return os; } template ostream& operator << (ostream& os, set& set_var) { for(typename set::iterator itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << " "; itr--; } return os; } void dump_func() {cout << endl;} template void dump_func(Head &&head, Tail &&... tail) { cout << head; if(sizeof...(Tail) > 0) cout << " "; dump_func(std::move(tail)...); } void swapRows(int mat[10005][55], int i, int j, int w) { for(int k = 1; k <= w+1; k++) swap(mat[i][k], mat[j][k]); } void GaussianElimination(int mat[10005][55], int w, int h) { int r = 1; for(int i = 1; i <= w && r <= h; i++){ if(mat[i][r] == 0){ int max_val = 0, max_j; for(int j = r+1; j <= h; j++){ if(mat[j][i] > max_val){ max_val = mat[j][i]; max_j = j; } } if(max_val == 0) goto end; swapRows(mat, r, max_j, w); } for(int j = 1; j <= h; j++){ if(j == r) continue; if(mat[j][i] == 0) continue; for(int k = 1; k <= w+1; k++){ mat[j][k] ^= mat[r][k]; } } r++; end:; } } ll n, m; ll ans[55]; int a[10005][55], b[10005]; int mat[10005][55]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(i, 1, m){ ll k, x; cin >> k; rep(j, 1, k) cin >> x, a[i][x] = 1; cin >> b[i]; } rep(i, 0, 29){ rep(j, 1, m){ rep(k, 1, n) mat[j][k] = a[j][k]; mat[j][n+1] = (b[j]>>i)&1; } GaussianElimination(mat, n, m); rep(j, 1, m){ ll p = n+1; rep(k, 1, n) if(mat[j][k]) chmin(p, k); if(p == n+1){ if(mat[j][n+1]){ outl(-1); return 0; } continue; } ans[p] |= mat[j][n+1]<