def main(): N = int(input()) XY = tuple(tuple(map(int, input().split())) for _ in [0] * N) z = XY[0][1] - XY[0][0] for x, y in XY: if z != y - x or z <= 0: print(-1) break else: print(z) main()