// ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter) { let n: usize = sc.next(); let m: usize = sc.next(); let mut cond = vec![]; for _ in 0..m { let a: usize = sc.next(); let mut b = 0u64; for _ in 0..a { let k = sc.next::() - 1; b |= 1 << k; } let y: u32 = sc.next(); cond.push((b, y)); } let mut base: Vec<(u64, u32)> = vec![]; for &(mut b, mut y) in cond.iter() { for &(p, q) in base.iter() { if b > (b ^ p) { b ^= p; y ^= q; } } if b > 0 { base.push((b, y)); } else if y > 0 { println!("-1"); return; } } base.sort(); let mut ans = vec![0; n]; for i in 0..base.len() { let (b, y) = base[i]; for (j, base) in base.iter_mut().enumerate() { if i != j && base.0 > b ^ base.0 { base.0 ^= b; base.1 ^= y; } } assert!(b.count_ones() == 1); let k = 64 - b.leading_zeros() as usize; ans[k - 1] = y; } for a in ans { writeln!(out, "{}", a).ok(); } }