import scala.collection.mutable.ListBuffer object Main { val sc = new java.util.Scanner(System.in) def readLine(): String = sc.nextLine def readInts(): Array[Int] = sc.nextLine.split(' ').map(_.toInt) def readInt(): Int = sc.nextLine.toInt def calc(xs: ListBuffer[(Int, Int)]) { val n = xs.head._2 - xs.head._1 if (n <= 0) { println(-1) return } for ((x, y) <- xs.tail) { if (n != y - x) { println(-1) return } } println(n) } def main(args: Array[String]) { val n = readInt val xs = new ListBuffer[(Int, Int)] for (i <- 0 to n-1) { val Array(x, y) = readInts xs.append((x, y)) } calc(xs) } }