def solve_linear_equation_F2_col(A,b): assert len(A)==len(b) n = len(A) for i in range(n): idx = max(range(i,n),key=lambda x:A[x]) if A[idx]==0: rank = i break if idx != i: A[i],A[idx] = A[idx],A[i] b[i],b[idx] = b[idx],b[i] for j in range(n): if i != j and A[j] > A[j]^A[i]: A[j] ^= A[i] b[j] ^= b[i] else: rank = n if any(b[i] for i in range(rank,n)): return [-1] ans = [0]*n for i in range(rank): ans[A[i].bit_length()-1] = b[i] return ans n,m = map(int,input().split()) A = [0]*m Y = [0]*m for i in range(m): _ = int(input()) *a, = map(int,input().split()) for ai in a: A[i] |= 1<<(ai-1) Y[i] = int(input()) x = solve_linear_equation_F2_col(A,Y) print(*x,sep="\n")