N = int(input())
x, y = map(int, input().split())
t = y - x
if t > 0:
    for i in range(0, N - 1, 1):
        x, y = map(int, input().split())
        if t != y - x:
            t = -1
            break
else:
    t = -1
print(t)