N, *XY = map(int, open(0).read().split()) XY = list(zip(*[iter(XY)] * 2)) a, b = XY[0] Z = b - a if all(y - x == Z for x, y in XY): print(Z) else: print(-1)