import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); List list = new ArrayList<>(); list.add(a[0]); for (int i = 1; i < n; i++) { if (a[i - 1] != a[i]) { list.add(a[i]); } } Set set = new HashSet<>(); for (Integer o : list) { set.add(o); } if (set.size() == list.size()) { System.out.println(0); } else { if (set.size() + 1 == list.size() && list.get(0).equals(list.get(list.size() - 1))) { System.out.println(1); } else { System.out.println(-1); } } } }