import java.util.Scanner object Problem185 { def main(args: Array[String]) { val sc = new Scanner(System.in) val N = sc.nextInt val XY = Seq.fill(N)((sc.nextInt, sc.nextInt)) val answer = XY.head._2 - XY.head._1 val result = XY.forall(xy => xy._2 - xy._1 == answer) match { case _ if answer <= 0 => -1 case true => answer case false => -1 } println(result) } }