// Learn more about F# at http://fsharp.org open System let rec ok (c: List) (seen: Set) = if c.IsEmpty then true else let x = c.Head if seen.Contains x then false else ok (c |> List.skipWhile (fun y -> y = x)) (seen.Add x) [] let main argv = let n = stdin.ReadLine() |> int let a = stdin.ReadLine().Split() |> Array.map (fun x -> int (x) - 1) |> Array.toList if (ok a (new Set([]))) then printfn "0" exit 0 let mutable freq = Array.create n 0 for x in a do freq.[x] <- freq.[x] + 1 if freq |> Array.forall (fun v -> v <= 1) then printfn "0" exit 0 let x = freq |> Array.findIndex (fun v -> v >= 2) let b = List.append (a |> List.skipWhile (fun y -> y = x)) (a |> List.takeWhile (fun y -> y = x)) printfn "%d" (if (ok b (new Set([]))) then 1 else -1) 0 // return an integer exit code