use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let mut a: Vec = it.map(|s| s.parse().unwrap()).collect(); a.dedup(); let mut id = vec![n; n + 1]; let mut ans = 0; for (i, &x) in a.iter().enumerate() { if id[x] != n { if a[0] == x && i == a.len() - 1 { ans = 1; } else { ans = -1; break; } } else { id[x] = i; } } println!("{}", ans); } fn main() { run(); }