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