fn main() { let n: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; let t: Vec = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let iter = buf.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect() }; let mut ans = -1; for d in 0..12 { let mut is_true = true; for i in 0..n { let mut is_included = false; for j in vec![0, 2, 4, 5, 7, 9, 11] { if t[i] == (d + j) % 12 { is_included = true; } } if !is_included { is_true = false; } } if is_true && ans < 0 { ans = d; } else if is_true { ans = -1; break; } } println!("{}", ans); }