N = int(input()) L = [] for _ in range(N): X, Y = map(int, input().split()) L += [Y - X] Z = L[0] print([-1, Z][set(L) == {Z} and Z > 0])