let N = stdin.ReadLine() |> int let r() = let arr = stdin.ReadLine().Split(' ') |> Array.map int in arr.[0] + arr.[1] * 4 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%2=1)) (0,false) l printfn "%d" (if b then -1 else (s/2))