package main import ( "bufio" "fmt" "os" "strconv" ) func main() { lines, max := input() result := count(lines, max) fmt.Println(result) } func input() ([]int, int) { N := nextInt() lines := make([]int, N) max := 0 for i := 0; i < N; i++ { a := nextInt() b := nextInt() lines[i] = a + b*4 if lines[i] > max { max = lines[i] } } return lines, max } func count(lines []int, max int) int { result := 0 for _, w := range lines { diff := max - w if diff%2 != 0 { return -1 } result += diff / 2 } return result } var sc = bufio.NewScanner(os.Stdin) func next() string { sc.Split(bufio.ScanWords) sc.Scan() return sc.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return i }