n,m = map(int,input().split()) l = max(n,m)+5 C = [0]*l Y = [0]*l for i in range(m): a = int(input()) B = list(map(int,input().split())) y = int(input()) Y[i] = y for b in B: C[i] |= 1<<(b-1) rank = 0 for i in range(n,-1,-1): for j in range(rank+1,m): if C[j] & 1 << i: C[rank],C[j] = C[j],C[rank] Y[rank],Y[j] = Y[j],Y[rank] break if not (C[rank] & 1 << i): continue for j in range(m): if j != rank and C[j] & 1<> j & 1: ans[j] = Y[i] break print(*ans,sep="\n")