fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: Vec = t.trim().split_whitespace().map(|s| s.parse::().unwrap() + 12usize).collect(); let melody: Vec = vec![0,2,4,5,7,9,11]; let result: Vec = (0..12) .filter(|i| n == t.iter().filter(|&v| melody.contains(&((v - i) % 12))).count()) .collect(); if result.len() == 1 { println!("{}", result[0]); } else { println!("{}", -1); } }