import java.util.Scanner; 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(); int[] c = new int[n + 1]; for (int i = 0; i < n - 1; i++) { if (c[a[i]]++ > 0) { System.out.println(-1); return; } } if (a[0] == a[n - 1]) { System.out.println(1); } else { System.out.println(0); } } }