use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let b = [0, 2, 4, 5, 7, 9, 11].to_vec(); let mut ans: i32 = -1; for d in 0..12 { let mut ok = true; for i in 0..n { let mut ng = true; for j in 0..7 { if (d + b[j]) % 12 == a[i] { ng = false; } } if ng { ok = false; } } if ok { if ans == -1 { ans = d as i32; } else { println!("-1"); return; } } } println!("{}", ans); }