N = int(input()) XY = [list(map(int, input().split())) for i in range(N)] res = -1 tmp = -1 res = [xy[1] - xy[0] for xy in XY] if res.count(res[0]) == N and res[0] > 0: print(res[0]) else: print(-1)