let N = stdin.ReadLine() |> int let r() = let arr = stdin.ReadLine().Split(' ') |> Array.map int64 in arr.[0] + arr.[1] * 4L let l = [ for x in 1..N -> r() ] let m = List.max l let s,b = List.fold (fun (s,b) n -> let x = m - n in (s+x, b||x%2L=1L)) (0L,false) l printfn "%d" (if b then -1L else (s/2L))