n, m = map(int, input().split()) X = [] Y = [] for _ in range(m): a = int(input()) B = list(map(int, input().split())) y = int(input()) bits = 0 for b in B: bits |= 1 << (b - 1) X.append(bits) Y.append(y) ans = [0] * n for i in range(30): base = [] oz = [] for x, y in zip(X, Y): z = (y >> i) & 1 for b, o in zip(base, oz): if x ^ b < x: x ^= b z ^= o if x == 0: if z: print(-1) exit() else: base.append(x) oz.append(z) for j in range(len(base) - 1, 0, -1): if base[j] > base[j - 1]: base[j], base[j - 1] = base[j - 1], base[j] oz[j], oz[j - 1] = oz[j - 1], oz[j] for b, o in zip(base[::-1], oz[::-1]): inds = [] for j in range(n): if b >> j & 1: inds.append(j) for j in inds[:-1]: o ^= ans[j] >> i & 1 if o: ans[inds[-1]] |= 1 << i print(*ans, sep="\n")