using System; using System.Collections.Generic; using System.Linq; namespace Problem1053 { class Program { static void Main(string[] args) { int N = GetInt(); var A = GetIntArray(); var list = new List(); int temp = 0; for(int i = 0; i < N; i++) { if(temp != A[i]) { list.Add(A[i]); temp = A[i]; } } var set = new HashSet(); if(list[0] == list[^1]) { list.RemoveAt(list.Count - 1); foreach(var value in list) { if(!set.Add(value)) { Console.WriteLine(-1); return; } } Console.WriteLine(1); } else { foreach (var value in list) { if (!set.Add(value)) { Console.WriteLine(-1); return; } } Console.WriteLine(0); } } public static int GetInt() => int.Parse(Console.ReadLine()); public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static double GetDouble() => double.Parse(Console.ReadLine()); public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray(); public static long GetLong() => long.Parse(Console.ReadLine()); public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray(); } }