import sequtils, strutils let n = parseInt readLine stdin xys = n.newSeqWith stdin.readLine.split.map parseInt ans = xys[0][1].pred xys[0][0] if ans < 1: echo -1 quit() for xy in xys: let x = xy[0] y = xy[1] if y.pred(x) != ans: echo -1 quit() echo ans